[😃, 🏀, 🍎, 🍇, 🐵].findLast(function(찾는_요소) {
    return 찾는_요소 === 과일;
}); // 👉 🍇

// 이 배열에서 찾는 요소의 조건인 과일(🍎, 🍇) 중 마지막 과일(🍇)이 반환됩니다.
// 배열을 생성합니다.
const numbers = [1, 3, 7, 4, 6, 8, 9];

// 조건(짝수)을 만족하는 마지막 요소를 찾습니다.
const lastEven = numbers.findLast(function(num) {
    return num % 2 === 0; // 짝수인지 확인
});

// 결과를 출력합니다.
console.log(lastEven); // 출력: 8
arr.findLast(callbackFn[, thisArg])
// 화살표 함수
findLast((element) => { /* … */ })
findLast((element[, index]) => { /* … */ })
findLast((element[, index[, array]]) => { /* … */ })

// 콜백 함수
findLast(callbackFn)
findLast(callbackFn[, thisArg])

// 인라인 콜백 함수
findLast(function (element) { /* … */ })
findLast(function (element[, index]) { /* … */ })
findLast(function (element[, index[, array]]) { /* … */ })
findLast(function (element[, index[, array]]) { /* … */ }[, thisArg])
callbackFn(element[, index[, array]])
/**
 * 콜백 함수
 *
 * @param {*} element 배열의 각 요소
 * @param {number} index 배열의 인덱스 (선택적)
 * @param {Array} array 원본 배열 (선택적)
 * @return {boolean} 필터링 조건을 충족하면 true, 그렇지 않으면 false 반환
 *
 * 콜백 함수는 기명 함수(사용자 정의 함수)나 익명 함수 등으로 사용할 수 있습니다.
 * (당연히) 모든 콜백 함수는 화살표 함수로 사용할 수 있습니다.
 */

/* 콜백 함수를 기명 함수를 사용할 경우 */
function callbackFn(element[, index[, array]]) { // 기명 함수 정의
    // return 문을 사용하여 조건을 정의합니다.
}

arr.findLast(callbackFn); // 정의한 기명 함수명을 매개변수에 직접 전달

/* 콜백 함수를 익명 함수로 사용할 경우 */
arr.findLast(function (element[, index[, array]]) {
    // return 문을 사용하여 조건을 정의합니다.
});
const numbers = [1, 2, 3, 4, 5, 3];
const target = 3;

// 조건을 만족하는 마지막 요소를 찾습니다.
const found = numbers.findLast(element => element === target);

// 결과에 따라 메시지를 출력합니다.
if (found !== undefined) {
    console.log(`찾는 값(${target})이 배열에 존재합니다. (뒤에서부터 찾음)`);
} else {
    console.log(`찾는 값(${target})이 배열에 존재하지 않습니다.`);
}

// 출력: 찾는 값(3)이 배열에 존재합니다. (뒤에서부터 찾음)
// 사람 객체 배열을 생성합니다.
const people = [
    {name: "Alice", age: 30},
    {name: "Bob", age: 25},
    {name: "Bob", age: 28},
    {name: "Charlie", age: 35}
];

// 찾고자 하는 이름을 변수로 정의합니다.
const targetName = "Bob";

// 배열 끝에서부터 name 속성이 targetName과 일치하는 마지막 사람 객체를 찾습니다.
const person = people.findLast(obj => obj.name === targetName);

// 결과를 출력합니다.
console.log(person); // 출력: {name: "Bob", age: 28}
// 상품 배열을 생성합니다.
const products = [
    {name: "Laptop", price: 1000},
    {name: "Phone", price: 200},
    {name: "Tablet", price: 300},
    {name: "Headphones", price: 500}
];

// 조건을 정의하는 콜백 함수를 만듭니다.
// 여기서는 가격이 600보다 작은 상품을 찾는 조건입니다.
const customCondition = product => product.price < 400;

// 배열에서 조건(customCondition)을 만족하는 마지막 상품을 찾습니다.
const affordableProduct = products.findLast(customCondition);

// 결과를 출력합니다.
console.log(affordableProduct); // 출력: {name: "Tablet", price: 300}