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.
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