[πŸ˜ƒ, πŸ€, πŸ…, 🐡].findIndex(function(item) {
    return item === πŸ€;
}) πŸ‘‰ 1 
/*
 * Note:
 * In arrays, indexes start at <code>0</code>.
 * The first element has an index of <code>0</code>, the second element has an index of <code>1</code>.
*/

// Create an array
const colors = ["red", "green", "blue"];

// Find the index of "green" in the array
const greenIndex = colors.findIndex(function(color) {
    return color === "green"; // Check if the array element equals "green"
});

// Output the result
console.log(greenIndex); // Output: 1
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
});
// Finding the position of a specific value
// Locate the position of a value in an array

const numbers = [1, 2, 3, 4, 5];
const target = 3;

// Use findIndex() to find the position of the value
const index = numbers.findIndex(num => num === target);

if (index !== -1) {
  console.log(`The position of ${target} is ${index + 1}.`);
} else {
  console.log(`The value ${target} was not found.`);
}

// Output: 'The position of 3 is 3.'
// Document list
const documents = [
    "JavaScript is a web programming language.",
    "You can build servers using Node.js.",
    "React is a popular frontend library.",
    "Python is a general-purpose programming language."
];

// Keyword to search for
const targetKeyword = "Node.js";

// Use findIndex() to find the first document containing the keyword
const index = documents.findIndex(document => document.includes(targetKeyword));

if (index !== -1) {
    console.log(`The first document containing "${targetKeyword}" is at position ${index + 1}.`);
} else {
    console.log(`No document containing "${targetKeyword}" was found.`);
}

// Output: 'The first document containing "Node.js" is at position 2'
// Real-time notification events
const notificationEvents = [
    {id: 1, message: "New message received", recipient: "Alice"},
    {id: 2, message: "Order completed", recipient: "Bob"},
    {id: 3, message: "Meeting started", recipient: "Charlie"},
    {id: 4, message: "Task reminder", recipient: "Alice"}
];

// Target user
const targetRecipient = "Alice";

// Use findIndex() to find the first notification for the user
const index = notificationEvents.findIndex(event => event.recipient === targetRecipient);

if (index !== -1) {
    const firstNotification = notificationEvents[index];
    console.log(`The first notification for "${targetRecipient}": ${firstNotification.message}`);
    // Here, you could add the logic to actually deliver the notification to the user
} else {
    console.log(`No notification found for "${targetRecipient}".`);
}

// Output: 'The first notification for "Alice": New message received'
// Real-time notification events
const notificationEvents = [
    {id: 1, message: "New message received", recipient: "Alice"},
    {id: 2, message: "Order completed", recipient: "Bob"},
    {id: 3, message: "Meeting started", recipient: "Charlie"},
    {id: 4, message: "Task reminder", recipient: "Alice"}
];

// Target user
const targetRecipient = "Alice";

// Use find() to get the first notification for the user
const firstNotification = notificationEvents.find(event => event.recipient === targetRecipient);

if (firstNotification) {
    console.log(`The first notification for "${targetRecipient}": ${firstNotification.message}`);
    // Here, you could add the logic to actually deliver the notification to the user
} else {
    console.log(`No notification found for "${targetRecipient}".`);
}

// Output: 'The first notification for "Alice": New message received'