Categories
JavaScript Answers

How to add break statement in JavaScript array map method?

Spread the love

Sometimes, we want to add break statement in JavaScript array map method.

In this article, we’ll look at how to add break statement in JavaScript array map method.

How to add break statement in JavaScript array map method?

To add break statement in JavaScript array map method, we can use the array some method.

For instance, we write

const hasValueLessThanTen = myArray.some((val) => {
  return val < 10;
});

to call myArray.some with a callback that checks if any items in myArray has value less than 10.

Conclusion

To add break statement in JavaScript array map method, we can use the array some method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *