How to add object to localstorage in JavaScript

Storage
Last updated Dec 19, 2017
const user = {
  id: 1,
  first_name: "John",
  last_name: "Doe"
};

localStorage.setItem("user", JSON.stringify(user));