| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Array/some | [Back] [Original] |
Get to know MDN better
Esta pgina foi traduzida do ingls pela comunidade. Saiba mais e junte-se comunidade MDN Web Docs.
This feature is well established and works across many devices and browser versions. Its been available across browsers since julho de 2015.
O mtodo some() testa se ao menos um dos elementos no array passa no teste implementado pela funo atribuda e retorna um valor true ou false.
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
arr.some(callback[, thisArg])
callbackFuno para testar cada elemento, recebendo trs argumentos:
currentValueO valor atual do elemento sendo processado no array.
indexO ndice do elemento atual sendo processado no array.
arrayO array onde o mtodo some() foi chamado.
thisArgOpcional. Valor para usar como this durante a execuo do callback.
Esta funo retorna true se a funo callback retornar true para qualquer elemento do array; caso contrrio, false.
some() executa a funo callback uma vez para cada elemento presente no array at achar um onde o callback retorne um valor true. Se em qualquer dos elementos o valor for encontrado, some() imediatamente retorna true. Caso contrario, some() retorna false. callback invocado somente para ndices do array que contenham valor definido; no invocado para ndices que foram deletados ou os quais nunca tiveram valor definido.
callback invocado com trs argumentos: o valor do elemento, o ndice do elemento, e o array onde a funo foi chamada.
Se o parmetro thisArg foi passado ao some(), ele sera passado ao callback quando o mesmo for invocado, para ser usado como o valor de this internamente na funo callback. Caso contrario, o valor undefined ser passado para uso como this. O valor this observado pela callback determinado de acordo com as regras usuais para determinar o que visto por uma funo.
some() no altera o array dentro do qual ele chamado.
O intervalo de elementos processado por some() definido antes da primeira invocao da callback. Elementos contidos no array antes da chamada some() ser iniciada no sero testados pela callback. Se algum elemento pertencente ao array for alterado pela callback, o valor passado para a callback ser o valor do momento em que a funo some() encontra o ndice daquele elemento. Elementos deletados no so testados.
O exemplo a seguir testa se algum elemento de um array maior que 10.
function isBiggerThan10(element, index, array) {
return element > 10;
}
[2, 5, 8, 1, 4].some(isBiggerThan10); // false
[12, 5, 8, 1, 4].some(isBiggerThan10); // true
Arrow functions fornece uma sintaxe mais curta para o mesmo teste.
[2, 5, 8, 1, 4].some((elem) => elem > 10); // false
[12, 5, 8, 1, 4].some((elem) => elem > 10); // true
some() was added to the ECMA-262 standard in the 5th edition; as such it may not be present in all implementations of the standard. You can work around this by inserting the following code at the beginning of your scripts, allowing use of some() in implementations which do not natively support it. This algorithm is exactly the one specified in ECMA-262, 5th edition, assuming Object and TypeError have their original values and that fun.call evaluates to the original value of Function.prototype.call().
// Production steps of ECMA-262, Edition 5, 15.4.4.17
// Reference: http://es5.github.io/#x15.4.4.17
if (!Array.prototype.some) {
Array.prototype.some = function (fun /*, thisArg*/) {
"use strict";
if (this == null) {
throw new TypeError("Array.prototype.some called on null or undefined");
}
if (typeof fun !== "function") {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++) {
if (i in t && fun.call(thisArg, t[i], i, t)) {
return true;
}
}
return false;
};
}
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-array.prototype.some |
This page was last modified on 24 de jun. de 2025 by MDN contributors.
ArrayArray.prototype.at()Array.prototype.concat()Array.prototype.copyWithin()Array.prototype.entries()Array.prototype.every()Array.prototype.fill()Array.prototype.filter()Array.prototype.find()Array.prototype.findIndex()findLast()findLastIndex()Array.prototype.flat()Array.prototype.flatMap()Array.prototype.forEach()Array.prototype.includes()Array.prototype.indexOf()Array.prototype.join()Array.prototype.keys()Array.prototype.lastIndexOf()Array.prototype.map()Array.prototype.pop()Array.prototype.push()Array.prototype.reduce()Array.prototype.reduceRight()Array.prototype.reverse()Array.prototype.shift()Array.prototype.slice()Array.prototype.some()Array.prototype.sort()Array.prototype.splice()Array.prototype.toLocaleString()toReversed()toSorted()toSpliced()Array.prototype.toString()Array.prototype.unshift()Array.prototype.values()with()Array.prototype[@@iterator]()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |