- objects.
- objects are collections of properties
- properties are a key-value pair
- use costom keys to access data rather than using an index.
- key-value pairs: property = key + value
- username: "smart_rich"
- upvotes: 7
- text: "nice vlog!"
- dictionay property. (一一对应)
- all types welcome.(可以多种类型混合存储)
- valid keys, all keys are converted to strings * (except for symbols)
- access data out of objects
-
const papers = { red : "shdkshdks" blue: "jshdjshdd" yellow: "sdhjshd" } papers.red papers['blue'] let color = 'red'; papers[color] // "shdkshdks"
-
- updating & adding properties
-
// To make an object literal: const dog = { name: "Rusty", breed: "unknown", isAlive: false, age: 7 } // All keys will be turned into strings! // To retrieve a value: dog.age; //7 dog["age"]; //7 //updating values dog.breed = "mutt"; dog["age"] = 8;
//addin a new property
dog["isHappy"] = true;Arrays + Objects
shoppingCart[2].product = "Fire Stick"