JavaScript Array some() Method

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








googletag.cmd.push(function() googletag.display('div-gpt-ad-1422003450156-2'); );



JavaScript Array some() Method


❮ JavaScript Array Reference



Example


Check if any values in the ages array are 18 or over:



var ages = [3, 10, 18, 20];

function checkAdult(age)
  return age >= 18;


function myFunction()

  document.getElementById("demo").innerHTML = ages.some(checkAdult);

<!--

The result will be:



true
-->
Try it Yourself »

More "Try it Yourself" examples below.



Definition and Usage


The some() method checks if any of the elements in an array pass a
test (provided as a function).


The some() method executes the function once for each element present in the
array:


  • If it finds an array element where the function returns a true value, some() returns true (and does not check the remaining values)

  • Otherwise it returns false

Note: some() does not execute the function for array
elements without values.


Note: some() does not change the original array.



Browser Support


The numbers in the table specify the first browser version that fully supports the method.















Method
some() Yes 9.0 Yes Yes Yes



Syntax



array.some(function(currentValue, index, arr), thisValue)

Parameter Values








Parameter Description
function(currentValue, index, arr) Required. A function to be run for each element in the array.
Function arguments:







Argument Description
currentValue Required. The value of the current element
index Optional. The array index of the current element
arr Optional. The array object the current element belongs to
thisValue Optional. A value to be passed to the function to be used as its "this" value.
If this parameter is empty, the value "undefined" will be passed as its "this" value






googletag.cmd.push(function() googletag.display('div-gpt-ad-1493883843099-0'); );





Technical Details






Return Value: A Boolean. Returns true if any of the elements in the array pass the test, otherwise it returns false
JavaScript Version: ECMAScript 3

More Examples




Example


Check if any of the values in the ages array are a specific number or over:



<p>Minimum age: <input type="number" id="ageToCheck" value="18"></p>

<button onclick="myFunction()">Try it</button>

<p>Any ages above: <span id="demo"></span></p>

<script>
var ages = [4, 12, 16, 20];

function checkAdult(age)
  return age >= document.getElementById("ageToCheck").value;


function myFunction()
  document.getElementById("demo").innerHTML = ages.some(checkAdult);


</script>

Try it Yourself »



❮ JavaScript Array Reference

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ