xxxxxxxxxx
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' }
xxxxxxxxxx
const inventory = [
{id: 23, quantity: 2},
{id: '24', quantity: 0},
{id: 25, quantity: 5}
];
// Check type and value using ===
const result = inventory.find( ({ id }) => id === 23 );
// Check only value using ==
const result = inventory.find( ({ id }) => id == 24 );
xxxxxxxxxx
const myArray = ["sun","moon","earth"];
const lookingFor = "earth"
console.log(myArray.find(planet => { return planet === lookingFor })
// expected output: earth
xxxxxxxxxx
array.include(numberWhichYouWantToFInd);
// if present it will return true otherwise false
xxxxxxxxxx
var ages = [3, 10, 18, 20];
function checkAdult(age) {
return age >= 18;
}
/* find() runs the input function agenst all array components
till the function returns a value
*/
ages.find(checkAdult);
xxxxxxxxxx
function include(arr, obj) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] == obj) return true;
}
}
console.log(include([1, 2, 3, 4], 3)); // true
console.log(include([1, 2, 3, 4], 6)); // undefined
Run code snippet
xxxxxxxxxx
public static void main(String[] args) {
int[] xr = {1, 2, 3, 4, 5};
int key = 3;
for (int i = 0; i < xr.length ; i++) {
if (key==xr[i]){
System.out.println("element is: "+i);
}
}
}
xxxxxxxxxx
// 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;
}
}