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

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -