JavaScript Complete Objects Tutorial Part 6 | JSON | Array in Object | Object in Array
JavaScript Complete Objects Tutorial Part 6 | JSON | Array in Object | Object in Array
Tutorial Cover:
1. How to Declare Objects in JavaScript
2. Access Value of Object
3. Access All Object Key Value Using For Loop
4. How to Create Array of Objects
5. How to Create Array inside Objects
6. Push Item in JSON Object Array
7. How to Add Item in JS Object
8. How to Change item in JS Object
9. JavaScript Complete JSON Tutorial
Tutorial Link : https://youtu.be/oXNPLoEZbaI
Join Our Telegram Group for Stay Updated : https://t.me/supercoders
var carsObject={"model":"2020","name":"Maruti","mileage":"20Km"}; //{"KEY":"Value"} console.log(carsObject); //print single value console.log(carsObject["model"]); console.log(carsObject.model); //changing the value carsObject['mileage']="30km"; console.log(carsObject); //for each loop for objects for(var key in carsObject){ console.log("Key : "+key+" value : "+carsObject[key]); } //adding value in object carsObject["yearold"]="5 Years"; console.log(carsObject); //Array of Objects var manycarObject=[{"model":"2020","name":"Maruti","mileage":"20Km"},{"model":"2010","name":"Tata","mileage":"25Km"}]; console.log(manycarObject); //Accessing first item Object console.log(manycarObject[0]["mileage"]); console.log("Car Names :"); for(var i=0;i<manycarObject.length;i++){ console.log("Name : "+manycarObject[i]["name"]); } for(var key in manycarObject){ console.log("Name : "+manycarObject[key]["name"]); } var listInObjects={"name":["Rahul","AMana","Vishal"]}; console.log(listInObjects); //Accessing list in object console.log(listInObjects["name"][0]); console.log(listInObjects["name"][1]); console.log(listInObjects["name"][2]); //all data access for(var key in listInObjects["name"]){ console.log(listInObjects["name"][key]); } //adding item into list listInObjects["name"].push("Ankit"); console.log(listInObjects);
No comments:
Post a Comment