Clone Array using `Array.from()` in JavaScript ( #shorts )

1 year ago
1

Hi Friends,

Clone Array using `Array.from()` in JavaScript

Cloning an Array using `Array.from()`:

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 originalArray = [1, 2, 3, 4, 5];

// Cloning using Array.from()
const clonedArray = Array.from(originalArray);

console.log(originalArray); // [1, 2, 3, 4, 5]
console.log(clonedArray); // [1, 2, 3, 4, 5]

#javascript #clone #clonearray #array #from #arrayfrom #javascriptarray #jsobject #jsarray #string #javascriptinterview #method #js #jquery #function #shorts #viral #popular #latest #new #famous #coders #development #code #dev #interview #php #trend #trending #answer #laravel #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...