Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can i extract from this array a new array in which the numbers between 5 and 6 are written

For example

let arr = [2,4,3,5,4,2,3,4,2,5,6];

I want to extract in new array this numbers 4,2,3,4,2,5

What I have tried:

I had the idea to use find to find the numbers 5 and 6 and search between them, but I didn't get the idea
Posted
Updated 1-Oct-22 5:21am

See JavaScript Arrays[^] for explanations of all the things you can do with an array.
 
Share this answer
 
Think about how you would do it manually: you would start at the left and look at each value until you found a 5. Then you would add each digit after that to a new piece of paper until you found a 6.
The new sheet of paper then contains the data you are looking for.

Then think about computerising it: you need a collection you can add to, a loop to look at individual characters, and a flag which tells you if you are looking for a 5 or a 6. if it's set to "start" then you look for a 5, if it's set to "end" you are copying up to a six.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900