How a Loop through a JavaScript object?
How a Loop through a JavaScript object?
Javascript Objects are Variables Containing Variables.
In JavaScript, an object is an entity, with property and type
In JavaScript objects the name:values pair are termed as properties.
var student = {studentName:”Jquery Training”, addrees:”Web”, age:02, type:”blog”};
<!DOCTYPE html> <html> <head> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script> </head> <body> How a Loop through a JavaScript object? <div id="preview"> </div> <script> var students = { "one": "50 students", "two": "30 students", "three":"70 students" }; for (var key in students) { if (students.hasOwnProperty(key)) { $('#preview').append('Class '+key + " : " + students[key]+"<br/>"); } } </script> </body> </html>
Storing Objects in HTML5 localStorage
<!DOCTYPE html> <html> <head> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script> </head> <body> Storing Objects in HTML5 localStorage <div id="preview-obj"> </div> <script> var testObject = { 'one': 1, 'two': 2, 'three': 3 }; var students = { "one": "50 students", "two": "30 students", "three":"70 students" }; localStorage.setItem('students', JSON.stringify(students)); var retrievedObject = localStorage.getItem('students'); var obj=JSON.parse(retrievedObject); for (var key in obj) { if (obj.hasOwnProperty(key)) { $('#preview-obj').append('Class '+key + " : " + obj[key]+"<br/>"); } } </script> </body> </html>