The syntax is:
arr.slice(start, end)
Slice method will returns a new array where it copies all items metioned from start index "start" to "end".
Both start and end can be negative, in this case position from array end is assumed.(like splice).
Below example can illustrate more...
let str = "test"; let arr = ["t", "e", "s", "t"]; alert( str.slice(1, 3) ); // es alert( arr.slice(1, 3) ); // e,s alert( str.slice(-2) ); // st alert( arr.slice(-2) ); // s,t
Things To Remember:
1. Remembering the syntax make you more stronger easily in javascript.
2. Slice end will not be added while slice operation.
3. Slice will return an array always.
4. Negative index position allowed.
No comments:
Post a Comment