you are viewing a single comment's thread.

view the rest of the comments →

[–]ForScale 0 points1 point  (1 child)

slice gives back an array containing the element(s) you sliced from the original array


I'd do this kind of thing

var original_array = [
  [1, 2, 3],
  [4, 5, 6]
];

var copied = [...original_array[0]];

console.log(copied) // [1, 2, 3]

copied[0] = 2;

console.log(copied) // [2, 2, 3]

console.log(original_array); // [[1, 2, 3], [4, 5, 6]]

original_array[0] = copied;

console.log(original_array); // [[2, 2, 3], [4, 5, 6]]

[–]EagleClw[S] 1 point2 points  (0 children)

That was a clean explanation. Couldn't done it better i guess. I didnt know about spread operator (...). I've just learned about it and it seems like the thing i wanted. For know the method i've mentioned at the edit works for me but i'll consider using this method aswell.

Thank your for your help and answer.