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

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

// Find the index of the first element that satisfies the condition (even number)
const firstEvenIndex = numbers.findIndex(function(num) {
    return num % 2 === 0; // check if the number is even
});

// Output the result
// The first element that satisfies the condition (even number) is 4,
// and its index is 3
console.log(firstEvenIndex); // Output: 3
arr.findIndex(callbackFn[, thisArg])
// Arrow function
findIndex((element) => { /* … */ })
findIndex((element[, index]) => { /* … */ })
findIndex((element[, index[, array]]) => { /* … */ })

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

// Inline callback function
findIndex(function (element) { /* … */ })
findIndex(function (element[, index]) { /* … */ })
findIndex(function (element[, index[, array]]) { /* … */ })
findIndex(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.findIndex(callbackFn); // Pass the defined named function directly as the argument

/* Using an anonymous function as the callback */
arr.findIndex(function (element[, index[, array]]) {
    // Define the condition using a return statement
});
// Array of user login history
const loginHistory = [
  { user: "Alice", date: "2025-01-01" },
  { user: "Bob", date: "2025-01-02" },
  { user: "Alice", date: "2025-01-05" },
  { user: "Charlie", date: "2025-01-06" },
  { user: "Alice", date: "2025-01-10" },
  { user: "Bob", date: "2025-01-12" }
];

// Target user
const targetUser = "Alice";

// Find the first login using findIndex()
const firstLoginIndex = loginHistory.findIndex(record => record.user === targetUser);

if (firstLoginIndex !== -1) {
  const firstLogin = loginHistory[firstLoginIndex];
  console.log(`First login:
    - User: ${firstLogin.user}
    - Date: ${firstLogin.date}`);
} else {
  console.log(`No login records found for ${targetUser}.`);
}

/* Output:
First login:
    - User: Alice
    - Date: 2025-01-01
*/