javascript - JS: Difference between simple number array and Array.slice() -
i wanna ask what's difference between normal number array: [1,2,3,4,5,6]
, [1,2,3,4,5,6].slice();
console.log([1,2,3,4,5,6].slice()); console.log([1,2,3,4,5,6]);
the result seems same, changes. want know is.
with slice()
(without arguments) function create shallow copy of original array.
var arr = [1,2,3,4,5,6]; arr === arr; // true arr === arr.slice(); // false
it may helpful when want clone array, operation on not modify original one.
Comments
Post a Comment