Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Javascript array&string slice function

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 www.tutorialstonight.com #
 
PREVIOUS NEXT
Tagged: #Javascript #slice #function
ADD COMMENT
Topic
Name
9+4 =