//Initialize object const obj = { 'width': 1000, 'pickle': 2000, 'fun': 3000, 'big': 4000};
let obj; obj = { 'width': 1000, 'pickle': 2000, 'fun': 3000, 'big': 4000}; //Now we "get" the value at the key //Syntax option 1 is "<object>.<key>" prn(obj.width); prn(obj.pickle); //Syntax option 2 is "<object>['key']" prn(obj['width']); prn(obj['pickle']);
let obj; //Two styles (similar to "gettingValues") //Syntax option 1 is "<object>.<key> = <value>" obj = {}; obj.width = '1000'; obj.height = '5'; prn(obj.width); prn(obj.height); //Syntax option 2 is "<object>['key'] = <value>" obj = {}; obj['cucumber'] = '5000'; obj['clown'] = '3'; prn(obj['cucumber']); prn(obj['clown']);
//Initialize object const obj = { 'width': 1000, 'pickle': 2000, 'fun': 3000, 'big': 4000}; //Iterate for (let key in obj){ prn(`key is "${key}", value is ${obj[key]}`); }