Object

Clone an object

1
const clone = Object.assign({}, original);
Copied!
Note: Doesn't do deep cloning. Use lodash or underscore

Iterate keys in an object (for...in)

1
const object = {x: 'a', y: 'b', z: 'c'}
2
for (const key in object) {
3
console.log(`${key}: ${object[key]}`);
4
}
Copied!
Result:
1
x: a
2
y: b
3
z: c
Copied!

Iterate values in an object (for...of)

Do not use `(for...of)` with `objects`. This will fatal with:
Safari:
1
TypeError: page[Symbol.iterator] is not a function. (In 'page[Symbol.iterator]()', 'page[Symbol.iterator]' is undefined)
Copied!
Chrome:
1
Uncaught TypeError: page[Symbol.iterator] is not a function
Copied!

Last modified 2yr ago