15,797,672 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[^]