How To Merge & Copy Objects - JavaScript Object Assign (In 2 Mins)

preview_player
Показать описание
The object "assign" function in JavaScript lets you merge and copy objects, which can come in handy for when doing things such as setting "default options" in other functions/methods.

For your reference, check this out:

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!

#dcode #javascript
Рекомендации по теме
Комментарии
Автор

Very helpful and to the point. I’m just breaking into objects{} in my studies and had that groundbreaking epiphany that nearly everything IS an object or a method of an object. Suddenly, “object-oriented” makes perfect sense.

leestanford
Автор

If I'm not completely wrong, "copied === me" returns false, since you're comparing an empty object to a non-empty object, right?

dancehalllyrics
Автор

Is there any effective difference with this and using the spread operator?

let me = { nameFirst: 'John', nameLast: 'Smith' };
let doppleganger = { ...me, nameFirst: 'John', nameLast: 'Smith' };
console.log({ me, doppleganger });

SilentBlueDragon