what is array find() in JavaScript

find() runs a function on every element in an array to find a element that returns a truthy value. If a truthy value isn’t returned undefined is returned.

The function passed into find() takes in these parameters:

An example of find() would be to find ‘orange’ in an array.

JavaScript

const fruits = ['apple', 'orange', 'banana'];
const findOrange = fruits.find((fruit, index, array) => {
    // apple, 0, ['apple', 'orange', 'banana']
    // orange, 1, ['apple', 'orange', 'banana']
    return fruit === 'orange';
});
console.log(findOrange);
// orange

summary of find()

find() is used to find an element in an array.

javascript
this in JavaScript

this refers to a object that is set is at the creation of a new execution context.

javascript
Constructors and Prototypes

In this blog, we're going to explore how JavaScript uses constructors as blueprints for the creation of many new objects, and prototypes for adding methods to objects.