“array.find bukan fungsi” Kode Jawaban

Temukan objek tertentu dari array di JS

let arr = [
    { name:"string 1", value:"this", other: "that" },
    { name:"string 2", value:"this", other: "that" }
];

let obj = arr.find(o => o.name === 'string 1');

console.log(obj);
Energetic Eland

array.find bukan fungsi

This may occur if the variable or value 
which .find() is called is not an array

To solve the error, 
1. make sure the variable or value is an array, if not
2. convert the value to an array before calling the .find() method

To convert to an array, use Array.from(value),


ADVANCED
To convert a nodelist to an array, visit this link
https://www.codegrepper.com/search.php?q=convert%20elements%20to%20array%20javascript
Code Rabbi

bagaimana menemukan id di array javascript

//The find() method returns the value of the first element in the provided array that satisfies the provided testing function.
const array1 = [5, 12, 8, 130, 44];

const found = array1.find(element => element > 10);

console.log(found);
// expected output: 12
Sleepy Swiftlet

Temukan metode javascript

const inventory = [
  {name: 'apples', quantity: 2},
  {name: 'bananas', quantity: 0},
  {name: 'cherries', quantity: 5}
];

function isCherries(fruit) { 
  return fruit.name === 'cherries';
}

console.log(inventory.find(isCherries)); 
// { name: 'cherries', quantity: 5 }
Clean Constrictor

Jawaban yang mirip dengan “array.find bukan fungsi”

Pertanyaan yang mirip dengan “array.find bukan fungsi”

Lebih banyak jawaban terkait untuk “array.find bukan fungsi” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya