-1

lets say we got an array and we want to get the 2-5 elements of it, is there a way we can do that like in python?

let test = ['a','b','c','d','e','f','g'];

in python we can do,

test[1:4]

and this will return us the 2nd to 5th elements does node offer a simple way to do this that way?

1
  • There is .slice() Commented Jun 30, 2022 at 10:41

1 Answer 1

0

You can just use the slice method:

let test = ['a','b','c','d','e','f','g'];
test.slice(1,4) // ['b', 'c', 'd' ]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.