Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
34
rated 0 times [  36] [ 2]  / answers: 1 / hits: 67752  / 12 Years ago, fri, january 18, 2013, 12:00:00

How to make this transformation?



[a,b,c,d,e] // => [c, d, e]


I was thinking that slice can do this, but..



[a,b,c,d,e].slice(2,-1) // [ 'c', 'd' ]
[a,b,c,d,e].slice(2,0) // []

More From » javascript

 Answers
27

Don't use the second argument:



Array.slice(2);





https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/slice




If end is omitted, slice extracts to the end of the sequence.



[#80784] Thursday, January 17, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominickmackenziet

Total Points: 583
Total Questions: 101
Total Answers: 117

Location: Saint Lucia
Member since Wed, Feb 8, 2023
1 Year ago
dominickmackenziet questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Fri, Feb 12, 21, 00:00, 3 Years ago
;