Array.form() will do the same operations and same behaviour as [...] spread.
for eg.
let nestedArray = [1, [2], 3]; let arrayCopy = Array.from(nestedArray);
// Make some changes arrayCopy[0] = '👻'; // change shallow element console.log(nestedArray); //[1,[2],3]
console.log(arrayCopy); // [ '👻',[2],3] arrayCopy[1][0] = '💩'; // change nested element console.log(nestedArray); // [ 1, [ '💩' ], 3 ]
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Array.form() will do the same operations and same behaviour as [...] spread.
for eg.
let nestedArray = [1, [2], 3];
let arrayCopy = Array.from(nestedArray);
// Make some changes
arrayCopy[0] = '👻'; // change shallow element
console.log(nestedArray); //[1,[2],3]
console.log(arrayCopy); // [ '👻',[2],3]
arrayCopy[1][0] = '💩'; // change nested element
console.log(nestedArray); // [ 1, [ '💩' ], 3 ]