12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

localStorageを使う事になった時にとりあえず見ればわかりそうなメモ

Posted at

スクリプト?なにそれ?
データベース?おいしいの?
という際に我々の強い味方になってくれるLocalStorageさん!!

※但しスマートフォンに限る

window.localStorage
if (window.localStorage) {
    // 保存する
    window.localStorage.setItem('key01', 'value01');
    window.localStorage.setItem('key02', 'value02');

    // じぇいそん行ってらっしゃい
    var json = {
            json_key01 : 'json_value01',
            json_key02 : 'json_value02'
    };
    window.localStorage.setItem('key03', JSON.stringify(json));

    // 取得する
    console.log(window.localStorage.getItem('key01'));
    console.log(window.localStorage.getItem('key02'));

    // お帰りじぇいそーん
    console.log(JSON.parse(window.localStorage.getItem('key03')));

    // キーを取得
    for (var i = 0; i < window.localStorage.length; i++) {
        console.log(window.localStorage.key(i));
    };

    // ☆(ゝω・)vクリア
    window.localStorage.clear();
}
12
12
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
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?