python dict.update() equivalent in javascript

You can use the destructuring assignment.

const first_dict = { 'key_one': 'value_one', 'key_two': 'value_two' } 
const second_dict = { 'key_one': 'value_from_second_dict', 'key_three': 'value_three' }

const accumulative = {
  ...first_dict,
  ...second_dict
}

console.log(accumulative)

/* 
[object Object] {
  key_one: "value_from_second_dict",
  key_three: "value_three",
  key_two: "value_two"
}
*/

Leave a Comment