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

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

// 조건(짝수)을 만족하는 첫 번째 요소를 찾습니다.
const firstEven = numbers.find(function(num) {
    return num % 2 === 0; // 짝수인지 확인
});

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

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

// 인라인 콜백 함수
find(function (element) { /* … */ })
find(function (element[, index]) { /* … */ })
find(function (element[, index[, array]]) { /* … */ })
find(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.find(callbackFn); // 정의한 기명 함수명을 매개변수에 직접 전달

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

// 조건을 만족하는 첫 번째 요소를 찾습니다.
const found = numbers.find(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: "Charlie", age: 35}
];

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

// 배열에서 name 속성이 targetName과 일치하는 첫 번째 사람 객체를 찾습니다.
const person = people.find(obj => obj.name === targetName);

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

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

// 배열에서 조건(customCondition)을 만족하는 첫 번째 상품을 찾습니다.
const affordableProduct = products.find(customCondition);

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