jsのhash(Object)をmergeする方法をたまに忘れちゃうのでメモ。
Object.assignを使う
test = {x: 1, y: 2, a: 3, b: 4}
console.log(Object.assign(test, {c: 5}))
> {x: 1, y: 2, a: 3, b: 4, c: 5}
3dots(Spread Operator)を使う
test = {x: 1, y: 2, a: 3, b: 4}
console.log({...test, c: 5})
> {x: 1, y: 2, a: 3, b: 4, c: 5}
Lodash/Underscoreを使う
test = {x: 1, y: 2, a: 3, b: 4}
console.log(_.merge(test, {c: 5}))
> {x: 1, y: 2, a: 3, b: 4, c: 5}