somascope
10/7/2018 - 2:45 PM

JavaScript Object

Object.assign

Copy all properties of an object to another object

  • Object.assign(target, ...sources)
  • Object.assign(this.form, stepData) // copies stepData object into the this.form object
  • Properties in the target object will be overwritten by properties in the sources if they have the same key.

Object.keys and Object.values

  • Creates an arraoy of every property's key or value in the object
  • const fruits = {apple: 28, orange: 17, pear: 54}
  • Object.keys(fruits) // [“apple”, “orange”, “pear”]
  • Object.values(fruits) // 28, 17, 54