array method return boolean
['one', 'two'].some(item => item === 'one') // true
['one', 'two'].some(item => item === 'three') // falseconst 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
let array = [1, 2, 3, 4, 5];
//Is any element even?
array.some(function(x) {
return x % 2 == 0;
}); // truelet obj = {"num1":1, "num2":2, "num3":3, "num4":4, "num5":5};
var firstEven = null;
// Some returns a boolean value.
Object.values(obj).some((item) => {
// Loop breaks as soon as the condition has been met.
// Getting your value, can be used like:
if (item == 2) {
firstEven = item;
}
return item % 2 == 0;
}); // Results in true
Also in JavaScript:
- what are callbacks
- remove angular cli
- javascript calculate age
- async iife
- how to give css style in javascript
- pageyoffset jquery
- node js do request
- column gap without affecting width site:stackoverflow.com
- chartjs min
- react native updating options with setoptions
- res : [ Circular ] nodejs
- object to query string javascript
- export { default as add } from './add.js'; ^^^^^^ SyntaxError: Unexpected token 'export'
- button not exist js
- jquery textarea autosize
- javascript boolean
- javascript generate function dynamically
- how to pass a variable to jspf
- jquery get data attribute of selected option
- javascript convert number to string
- loop through json array python
- Javascript check if undefined
- map over object javascript
- how to save thing in cookie js