Clone Object Or Array using spread operator in JavaScript ( #shorts )

1 year ago
1

Hi Friends,

Clone Object Or Array using spread operator in JavaScript

Cloning an object using the spread operator (...):

This method create a shallow clone. That way it create only a new reference to the original object/array. Any change made to the original object/array will not make any affect to this new object/array. If the original object or array contains nested objects or arrays, they will still be referenced and not cloned deeply.

const originalObj = { name: 'john', gender: 'male' };

// Cloning using the spread operator
const clonedObj = { ...originalObj };

console.log(originalObj); // { name: 'john', gender: 'male' }
console.log(clonedObj); // { name: 'john', gender: 'male' }

#javascript #clone #cloneobject #clonearray #cloneobjectarray #object #array #javascriptobject #javascriptarray #jsobject #jsarray #string #javascriptinterview #method #js #jquery #function #shorts #viral #popular #latest #new #famous #coders #development #code #dev #interview #php #trend #trending #answer #youtube #instagram #socialmedia #education #edit #gaming #how #india #knowledge #love #like #motivational #quiz #reels #short #subscribe #share #update #video #web #webdeveloper #website #webdesign #ytshorts #youtuber #princecheema_official @princecheema_official

Loading comments...