Skip to content

Instantly share code, notes, and snippets.

@Dosant
Created March 13, 2017 07:59
Show Gist options
  • Save Dosant/7f24f97e07aa870fc62f0fb0357f23ba to your computer and use it in GitHub Desktop.
Save Dosant/7f24f97e07aa870fc62f0fb0357f23ba to your computer and use it in GitHub Desktop.
var articles = [{
"id": "news/2017/02/28/rossiya-snimet-zapret-na-import-moldavskih-vin",
"title": "Россия снимет запрет на импорт молдавских вин",
"author": "sports",
"createdAt": "2017-02-28T05:24:23.856Z",
"content": "Content of post",
"summary": "Summary of post"
}];
// Сериализуем его
var articlesString = JSON.stringify(articles)
// После этого articlesString принимает строковое значение
// Запишем в localStorage с ключём object
localStorage.setItem("articles", articlesString);
// Обратимся к localStorage следующим образом
// Хранилище вернёт нашу сериализованную строку
var articlesString2 = localStorage.getItem("articles");
// преобразуем к обычному объекту JavaScript
var articles2 = JSON.parse(articlesString2)
// В итоге объекты articles1 и articles2 абсолютно одинаковы
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment