15,849,406 members
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 6:21am

## Solution 1

See JavaScript Arrays[^] for explanations of all the things you can do with an array.

## Solution 2

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[^]

Top Experts
Last 24hrsThis month
 Richard MacCutchan 60 Graeme_Grant 40 OriginalGriff 30 Maxim Kartavenkov 20 merano99 20
 OriginalGriff 20 Richard MacCutchan 10 merano99 10 Maxim Kartavenkov 10 Dave Kreskowiak 10

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