Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

. slice function javascrpit

const a=[1,2]
//const b=a
//above line makes b point to same object in heap as a

To create a copy of a we can write this instead:
const b=a.slice()
// b now contains it's own object [1,2] in heap

Note:slice method is similar(but a little different) to slice operator in python
For ex. unlike slice operator(python), js slice method only accepts 2 arguments.
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #slice #function #javascrpit
ADD COMMENT
Topic
Name
6+3 =