[πŸ˜ƒ, πŸ€, 🍎, πŸ‡, 🐡].find(function(item) {
    return item === fruit;
});
// πŸ‘‰ 🍎

// In this array, among the elements that meet the condition of being a fruit (🍎, πŸ‡),
// the first matching fruit (🍎) is returned.
// Create an array
const numbers = [1, 3, 7, 4, 6, 8];

// Find the first even number
const firstEven = numbers.find(function(num) {
    return num % 2 === 0; // check if the number is even
});

// Output the result
console.log(firstEven); // Output: 4
arr.find(callbackFn[, thisArg])
// Arrow function
find((element) => { /* … */ })
find((element[, index]) => { /* … */ })
find((element[, index[, array]]) => { /* … */ })

// Callback function reference
find(callbackFn)
find(callbackFn[, thisArg])

// Inline callback function
find(function (element) { /* … */ })
find(function (element[, index]) { /* … */ })
find(function (element[, index[, array]]) { /* … */ })
find(function (element[, index[, array]]) { /* … */ }[, thisArg])
callbackFn(element[, index[, array]])
/**
 * Callback function
 *
 * @param {*} element Each element in the array
 * @param {number} index Optional. The index of the element
 * @param {Array} array Optional. The original array
 * @return {boolean} Returns true if the condition is met, otherwise false
 *
 * The callback function can be a named function (user-defined) or an anonymous function.
 * All callback functions can also be written as arrow functions.
 */

/* Using a named function as the callback */
function callbackFn(element[, index[, array]]) { // Named function definition
    // Define the condition using a return statement
}

arr.find(callbackFn); // Pass the defined named function directly as the argument

/* Using an anonymous function as the callback */
arr.find(function(element[, index[, array]]) {
    // Define the condition using a return statement
});
const numbers = [1, 2, 3, 4, 5];
const target = 3;

// Find the first element that satisfies the condition
const found = numbers.find(element => element === target);

// Output a message based on the result
if (found !== undefined) {
    console.log(`The value (${target}) exists in the array.`);
} else {
    console.log(`The value (${target}) does not exist in the array.`);
}

// Output: The value (3) exists in the array.
// Create an array of person objects
const people = [
    {name: "Alice", age: 30},
    {name: "Bob", age: 25},
    {name: "Charlie", age: 35}
];

// Define the name to search for
const targetName = "Bob";

// Find the first person object in the array whose name matches targetName
const person = people.find(obj => obj.name === targetName);

// Output the result
console.log(person); // Output: {name: "Bob", age: 25}
// Create an array of products
const products = [
    {name: "Laptop", price: 1000},
    {name: "Phone", price: 500},
    {name: "Tablet", price: 300}
];

// Define a callback function for the condition
// Here, the condition is to find a product with a price less than 600
const customCondition = product => product.price < 600;

// Find the first product in the array that satisfies the customCondition
const affordableProduct = products.find(customCondition);

// Output the result
console.log(affordableProduct); // Output: {name: "Phone", price: 500}