“array.some ()” Kode Jawaban

JS menemukan array kembali benar -benar salah

['one', 'two'].some(item => item === 'one') // true
['one', 'two'].some(item => item === 'three') // false
foloinfo

javascript beberapa

const fruits = ['apple', 'banana', 'mango', 'guava'];

function checkAvailability(arr, val) {
  return arr.some(function(arrVal) {
    return val === arrVal;
  });
}

checkAvailability(fruits, 'kela');   // false
checkAvailability(fruits, 'banana'); // true
Dangerous Dogfish

array.some ()

<script>
  
// JavaScript code for some() function 
function isodd(element, index, array) {  
    return (element % 2 == 1);  
} 
    
function geeks() { 
    var arr = [ 6, 1, 8, 32, 35 ]; 
      
    // check for odd number 
    var value = arr.some(isodd); 
    console.log(value); 
} 
geeks(); 
</script>
Helpless Hummingbird

JavaScript array beberapa

function isBiggerThan10(element, index, array) {
  return element > 10;
}

[2, 5, 8, 1, 4].some(isBiggerThan10);  // false
[12, 5, 8, 1, 4].some(isBiggerThan10); // true
Clever Crocodile

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya