bhylu.com

Advertisements

JS Array Search

Find returns the first matching item. FindIndex returns its index; includes checks whether a value is present.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const prices = [4, 7, 12];
console.log(prices.find(price => price > 5));
console.log(prices.includes(12));

What happens

The first matching price is 7 and 12 is present.