Skip to main content Accessibility Feedback

JSON

JSON.stringify()

Convert object or array data into a string.

// Save an object
let lunch = {
	sandwich: 'turkey',
	chips: 'Cape Cod',
	drink: 'Pepsi'
};
localStorage.setItem('lunchOrder', JSON.stringify(lunch));

// Save an array
let drinks = ['Pepsi', 'water', 'lemonade'];
localStorage.setItem('drinkOptions', JSON.stringify(drinks));

Join the Lean Web Club! Coaching. Courses. Coding resources. Get the skills, confidence, and support you need to learn front-end web development and achieve long-term success.


Find this useful? You can support my work by purchasing an annual membership.