Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (31 sloc) 893 Bytes

Object

Clone an object

const clone = Object.assign({}, original);

Note: Doesn't do deep cloning. Use lodash or underscore

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

  const object = {x: 'a', y: 'b', z: 'c'}
  for (const key in object) {
    console.log(`${key}: ${object[key]}`);
  }

Result:

x: a
y: b
z: c

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of

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

Do not use `(for...of)` with `objects`. This will fatal with:

Safari:

TypeError: page[Symbol.iterator] is not a function. (In 'page[Symbol.iterator]()', 'page[Symbol.iterator]' is undefined)

Chrome:

Uncaught TypeError: page[Symbol.iterator] is not a function

You can’t perform that action at this time.