F
F
freshik3122018-10-29 18:43:12
JavaScript
freshik312, 2018-10-29 18:43:12

How to make a loop within a loop synchronously?

Hello,
I need to make a loop, in a loop, so that it would work synchronously
, I have:

const arr = [1,2,3,4,5]
for(const item of arr){
   console.log('check: ' + item)
   if(something !== NULL){  //тут моя проверка
      const arr2 = [a,b,c]
      for(const item2 of arr2){
         console.log('item: ' + item2);
      }
   }
}

expected result:
spoiler
check: 1
   item: a
   item: b
   item: c
check: 2
   item: a
   item: b
   item: c
check: 3
   item: a
   item: b
   item: c
check: 4
   item: a
   item: b
   item: c
check: 5
   item: a
   item: b
   item: c

I get:
spoiler
check: 1
check: 2
check: 3
check: 4
check: 5
   item: a
   item: b
   item: c
   item: a
   item: b
   item: c
   item: a
   item: b
   item: c
   item: a
   item: b
   item: c
   item: a
   item: b
   item: c

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2018-10-29
@ilyapashkov02

That's how it works for you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question