Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript array any

const array = [1, 2, 3, 4, 5];
// checks whether an element is even
const even = (element) => element % 2 === 0;
console.log(array.some(even));
// expected output: true
Comment

array any

// 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 any array

 
// There's no isEmpty or any method. 
// You can define your own .isEmpty() or .any()

Array.prototype.isEmpty = function() {
    return this.length === 0;
}

Array.prototype.any = function(func) {
   return this.some(func || function(x) { return x });
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: cypress visible 
Javascript :: how to check for enter keyPress in react native 
Javascript :: javascript for loop[ 
Javascript :: dynamic regex javascript 
Javascript :: javascript last in a list 
Javascript :: arrow functions in js 
Javascript :: vanilla js send get request 
Javascript :: javascript break with Nested Loop 
Javascript :: importing svg into cra 
Javascript :: how to get the text of a clicked elemet by javascript 
Javascript :: sanitize data within an Express application 
Javascript :: how to do an isogram in javascript 
Javascript :: javascript set color in hex 
Javascript :: vue js encrypt localstorage data 
Javascript :: sort by attribute in reactjs 
Javascript :: if statement in react native 
Javascript :: change all a tag href javascript 
Javascript :: react cors error 
Javascript :: react particles 
Javascript :: JQuery datatable with ajax, post API call hook 
Javascript :: javascript escape single quote 
Javascript :: capitalize each word from string in react 
Javascript :: browseranimationsmodule browsermodule has already been loaded 
Javascript :: how to use json stringify in javascript 
Javascript :: linear equations calculator 
Javascript :: overflowy javascript 
Javascript :: like in mongodb 
Javascript :: variables javascript 
Javascript :: Put Variable Inside JavaScript String 
Javascript :: why does javascript have hoisting 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =