Index
Examples


Constructing and initializing a plain object

//Initialize object
const obj = { 'width': 1000, 'pickle': 2000,
				'fun': 3000, 'big': 4000};
Getting values from simple object

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']);
Setting values into the object

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']);
Iterating over the object properties

//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]}`);
}

More Example Sources


Here are a couple (among many more) online related example sources: