indexOf()
Returns the first index at which a given element can be found.
Example:
let fruits = ['Apple', 'Banana', 'Mango'];
let index = fruits.indexOf('Banana');
console.log(index); // Output: 1
find()
Returns the value of the first element that satisfies the provided testing function.
Example:
let numbers = [1, 2, 3, 4, 5];
let found = numbers.find(function(number) {
return number > 3;
});
console.log(found); // Output: 4
findIndex()
Returns the index of the first element that satisfies the provided testing function.
Example:
let numbers = [1, 2, 3, 4, 5];
let index = numbers.findIndex(function(number) {
return number > 3;
});
console.log(index); // Output: 3
includes()
Determines whether an array includes a certain value.
Example:
let fruits = ['Apple', 'Banana', 'Mango'];
let hasBanana = fruits.includes('Banana');
console.log(hasBanana); // Output: true