// .find method only accepts a callback function
// and returns the first value for which the function is true.
const cities = [
"Orlando",
"Dubai",
"Denver",
"Edinburgh",
"Chennai",
"Accra",
"Denver",
"Eskisehir",
];
const findCity = (element) => {
return element === "Denver";
};
console.log(cities.find(findCity));
//Expected output is 4 (first instance of "Denver" in array)
const inventory = [
{id: 23, quantity: 2},
{id: '24', quantity: 0},
{id: 25, quantity: 5}
];
// Check type and value using ===
const result = inventory.find( ({ id }) => id === 23 );
// Check only value using ==
const result = inventory.find( ({ id }) => id == 24 );
var ages = [3, 10, 18, 20];
function checkAdult(age) {
return age >= 18;
}
/* find() runs the input function agenst all array components
till the function returns a value
*/
ages.find(checkAdult);
const list = [5, 12, 8, 130, 44];
// a find metóduson belül a number egy paraméter
// azért nem szükséges köré a zárójel, mert csak egy paramétert adunk át
// minden más esetben így kell írni:
// const found = list.find((index, number) => number > index);
const found = list.find(number => number > 10);
console.log(found);
// --> 12
//find is higher oder function that return only if condition is true
const names= ["Shirshak","SabTech","Kdc"]
const searchName = names.find(function(name){
return names.inclues("Shirshak")
})
str.indexOf("locate"); // return location of first find value
str.lastIndexOf("locate"); // return location of last find value
str.indexOf("locate", 15); // start search from location 15 and then take first find value
str.search("locate");
//The search() method cannot take a second start position argument.
//The indexOf() method cannot take powerful search values (regular expressions).