How to use find() method In ES6

The find() method is used to iterate through all the entries of the array and returns the record matching with a particular condition.

Example: To demonstrate finding an object where flag is 0.

javascript
let objects = [
    { flag: 1, a: 1 },
    { flag: 0, a: 2 },
    { flag: 1, a: 3 }
];

// Use find() function to
// filter the object
objects.find((object) => {

    if (object.flag === 0) {

        // Display the result
        console.log("flag:" + object.flag
            + ", a:" + object.a);
    }
});

Output
flag:0, a:2


Array Helper Methods in ES6

Array helper methods in ES6 (JavaScript) are extremely useful for working with data stored in arrays. As a web developer, you often work with arrays, whether they contain simple numbers or complex objects with many attributes. These methods significantly simplify the manipulation of arrays, making it easier to perform complex tasks and handle intricate arrays of objects.

There are several array methods available in JavaScript ES6 which are as follows:

Table of Content

  • Using forEach() method
  • Using map() method
  • Using filter() method
  • Using find() method

Similar Reads

Using forEach() method

The forEach() method is used to iterate over all the entries of the array....

Using map() method

The map() method is used to iterate through all the entries of the array, modifies them and returns a new array but the old array is not manipulated....

Using filter() method

The filter() method is used to iterate through all the entries of the array and filters out required entities into another array....

Using find() method

The find() method is used to iterate through all the entries of the array and returns the record matching with a particular condition....