1// iterates over all enumerable properties of an object that are
2// keyed by strings (ignoring ones keyed by Symbols),
3// including inherited enumerable properties.
4
5const object = { a: 1, b: 2, c: 3 };
6
7for (const property in object) {
8 console.log(`${property}: ${object[property]}`);
9}
10
11// expected output:
12// "a: 1"
13// "b: 2"
14// "c: 3"
1//You need to make the object first, then use [] to set it.
2
3var key = "happyCount";
4var obj = {};
5obj[key] = someValueArray;
6myArray.push(obj);
1//For ES6 and Babel
2{
3 [yourKeyVariable]: "yourValue",
4}
5
6// ES5 Alternative
7// Create the object first, then use [] to set your variable as a key
8var yourObject = {};
9
10yourObject[yourKeyVariable] = "yourValue";