Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript some

const age= [2,7,12,17,21];

age.some(function(person){
return person > 18;}); //true

//es6
const age= [2,7,12,17,21];
age.some((person)=> person>18); //true
Comment

array some

// Use method "some" to loop through array elements and see if there are any matching ones
const array = [{ name: 'Dharmesh', gender: 'male' }, { name: 'Priti', gender: 'female' }];
const hasFemaleContender = array.some(({ gender }) => gender === 'female');
console.log(hasFemaleContender);
Comment

js array.some

// an array
const array = [ 1, 2, 3, 4, 5 ];

// check if any of the elements are less than three (the first two are)
array.some(function(element) {
	return element < 3;
}); // -> true
// ES6 equivalents
array.some((element) => {
	return element < 3
}); // -> true
array.some((element) => element < 3); // -> true
Comment

javascript some method

It just checks the array,
for the condition you gave,
if atleast one element in the array passes the condition
then it returns true
else it returns false
Comment

javascript array some

let array = [1, 2, 3, 4, 5];

//Is any element even?
array.some(function(x) {
  return x % 2 == 0;
}); // true
Comment

javascript some

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
Comment

js some

movies.some(movie => movie.year > 2015)
// Say true if in movie.year only one (or more) items are greater than 2015
// Say false if no items have the requirement (like and operator)
Comment

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>
Comment

javascript array some

var nums = [1, 2, 3, 4, 5, 6, 7];

function even(ele)
{
    return ele%2 == 0;
    
}
console.log(nums.some(even))
/*consol.log will show true because at least one of the elements is even*/
Comment

Javascript array some

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

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

JavaScript Array some()

const numbers = [45, 4, 9, 16, 25];
let someOver18 = numbers.some(myFunction);

function myFunction(value, index, array) {
  return value > 18;
}
Comment

some of array js

function sum(numbers) {
  return numbers.reduce((a, b) => a + b, 0);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: id button click jquery 
Javascript :: javascript unknown number of parameters 
Javascript :: javascript less than but greater than 
Javascript :: javascript array sorting 
Javascript :: Random number given a range js 
Javascript :: Error: ENOENT: no such file or directory, lstat ode_modules@react-navigationcoresrcgetStateFromPath.tsx 
Javascript :: compare date javascript 
Javascript :: Javascript using forEach loop to loop through an array 
Javascript :: how to append data to a form data in javascript 
Javascript :: ejs to javascript array 
Javascript :: decode raw data to string nodejs 
Javascript :: reactjs lifecycle class components 
Javascript :: jquery determine empty value radio by name 
Javascript :: react chartjs 2 
Javascript :: setstate in react 
Javascript :: permutation and combination program in javascript 
Javascript :: updating an array of object in mongoose 
Javascript :: get file css code with javascript 
Javascript :: javascript swap array elements 
Javascript :: javascript cookies vs session vs local storage 
Javascript :: append string js 
Javascript :: iterating string js 
Javascript :: get file extension in javascript 
Javascript :: javascript minute and second to convert seconds 
Javascript :: address 
Javascript :: how to set expire time of jwt token in node js 
Javascript :: multiple class to same click jquery 
Javascript :: alternative way to handle React routes in a separate file 
Javascript :: make a function and return the index of specific character in javascript 
Javascript :: React social login button 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =