![]() forEach() not only makes your code shorter, but also makes your intent clearer. If you need a list of all matches, then you should use. If more values match your condition, it won’t matter. some(), the only difference is that we changed some for find ! But now, instead of returning a boolean, it will return the first pilot in our list. Here’s a list of operatives working for your super secret organization: var operatives = [ ) Įven shorter with ES6’s arrow functions: const firstPilot = operatives.find(operative => operative.pilot) Īs you can see the code is exactly the same as with. If that doesn’t sound clear to you, let me illustrate with an example… ![]() This array method helps you determine if one or more of its values correspond to something you’re looking for. filter(), I thought I should share two more array methods that are useful tools in a JavaScript developer’s arsenal. ![]() find()įollowing the insane amount of views on my article on. ![]()
0 Comments
Leave a Reply. |