Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get specific subarray of a bigger array in node.js

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can just use the slice method:

let test = ['a','b','c','d','e','f','g'];
test.slice(1,4) // ['b', 'c', 'd' ]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading