Skip to content

Javascript useful things

Clone and merge objects

MDN Object assign

js
// clone
const copy = Object.assign({}, obj);
// merge
const merged = Object.assign(o1, o2, o3);

Find in array

MDN Find

js
const item = items.find(p => p.id === 1);