0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ブラウザのコンソールからウェブストレージの値を変更するサンプルコード

Last updated at Posted at 2024-10-06

概要

ブラウザのコンソールからウェブストレージの値を変更する用のサンプルコードのメモです

セッションストレージ

  • 新規追加

     const data = {sample: "hoge"}
     sessionStorage.setItem('sample_key', JSON.stringify(data))
    
  • 変更

     const data = JSON.parse(sessionStorage.getItem("sample_key"))
     data.sample = "foo"
     sessionStorage.setItem("sample_key", JSON.stringify(data))
    

ローカルストレージ

  • 新規追加

     const data = {sample_key: "hoge"}
     localStorage.setItem('sample_key', JSON.stringify(data))
    
  • 変更

     const data = JSON.parse(localStorage.getItem('sample_key'))
     data.sample = "foo"
     localStorage.setItem('sample_key', JSON.stringify(data))
    
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?