Cannot break for-loop: Unsyntactic break

Like you yourself suggested, you are still in the map part. That is actually an arrow function expression and you are no longer in in the loop. Think of it as some function you defined elsewhere, but it's a quicker way of calling that function.

You are not using the map function as it is meant to be used in javascript. It isn't meant to be a convenient way to iterate over an array, but rather create a new array from some other array. You should change your usage of map to some form of a loop


To fix this problem you can simply use return; instead of break;


You can't use break with methods like map, reduce, forEach, etc. But you can .filter your data before or just .find the element you need

Tags:

Javascript