“Cari di Array JavaScript” Kode Jawaban

Temukan elemen dalam array javascript

const simpleArray = [3, 5, 7, 15];
const objectArray = [{ name: 'John' }, { name: 'Emma' }]

console.log( simpleArray.find(e => e === 7) )
// expected output 7

console.log( simpleArray.find(e => e === 10) )
// expected output undefined

console.log( objectArray.find(e => e.name === 'John') )
// expected output { name: 'John' }
Inquisitive Impala

JavaScript menemukan

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

const result = inventory.find( ({ name }) => name === 'cherries' );

console.log(result) // { name: 'cherries', quantity: 5 }
Real Rattlesnake

Elemen JavaScript di Array

var fruits = ["Banana", "Orange", "Apple", "Mango"];

var n = fruits.includes("Mango");
Brave Bear

JavaScript Temukan objek dalam array

myArray.findIndex(x => x.id === '45');
muchlisoft

temukan dalam fungsi array

const persons = [
  {name:"Shirshak",gender:"male"},
  {name:"Amelia",gender:"female"},
  {name:"Amand",gender:"male"}
]
//filter return all objects in array
let male = persons.filter(function(person){
return person.gender==='male'
})
console.log(male) //[{name:"Shirshak",gender:"male"},{name:"Amand",gender:"male"}]

//find return first object that match condition
let female = persons.find(function(person){
return person.gender==='female'
})
Sab Tech

Cari di Array JavaScript

// easyui

function cekNilai9box(value,row){
    var getData = row.compare_nilai9box;
    var assesment = getData.split(',');
    var cek = assesment.find(e => e == row.nilai9box_value_ori);
    
    if(cek == undefined){
        return '<span style="color:red;">'+ value +'</span>';
    }else{
        return value;
    }
}
Satriags

Jawaban yang mirip dengan “Cari di Array JavaScript”

Pertanyaan yang mirip dengan “Cari di Array JavaScript”

Lebih banyak jawaban terkait untuk “Cari di Array JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya