| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Array/every | [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 every() testa se todos os elementos do array passam pelo teste implementado pela funo fornecida. Este mtodo retorna um valor booleano.
const isBelowThreshold = (currentValue) => currentValue < 40;
const array1 = [1, 30, 39, 29, 10, 13];
console.log(array1.every(isBelowThreshold));
// Expected output: true
arr.every(callback[, thisArg])
callbackFuno que testa cada elemento, recebe trs parametros:
currentValue (obrigatrio)O elemento atual sendo processado na array.
index (opcional)O ndice do elemento atual sendo processado na array.
array (opcional)O array de origem.
thisArgOpcional. Valor a ser usado como this quando o callback executado.
true se a funo de callback retorna um valor truthy para cada um dos elementos do array; caso contrrio, false.
O mtodo every executa a funo callback fornecida uma vez para cada elemento presente no array, at encontrar algum elemento em que a funo retorne um valor false (valor que se torna false quando convertido para boolean). Se esse elemento encontrado, o mtodo every imediatamente retorna false. Caso contrrio, se a funo callback retornar true para todos elementos, o mtodo retorna true. A funo callback chamada apenas para os elementos do array original que tiverem valores atribudos; os elementos que tiverem sido removidos ou os que nunca tiveram valores atribudos no sero considerados.
A funo callback chamada com trs argumentos: o valor do elemento corrente, o ndice do elemento corrente e o array original que est sendo percorrido.
Se o parmetro thisArg foi passado para o mtodo every, ele ser repassado para a funo callback no momento da chamada para ser utilizado como o this. Caso contrrio, o valor undefined ser repassado para uso como o this. O valor do this a ser repassado para o callback determinado de acordo com as regras usuais para determinar o this visto por uma funo.
O mtodo everyno modifica o array original.
A lista de elementos que sero processados pelo every montada antes da primeira chamada da funo callback. Se um elemento for acrescentado ao array original aps a chamada ao every , ele no ser visvel para o callback. Se os elementos existentes forem modificados, os valores que sero repassados sero os do momento em que o mtodo every chamar o callback. Elementos removidos no sero considerados.
every funciona como o qualificador "for all" em matemtica. Particularmente, para um vetor vazio, retornado true. ( verdade por vacuidade que todos os elementos do conjunto vazio satisfazem qualquer condio.)
O exemplo a seguir testa se todos elementos no array so maiores que 10.
function isBigEnough(element, index, array) {
return element >= 10;
}
[12, 5, 8, 130, 44].every(isBigEnough); // false
[12, 54, 18, 130, 44].every(isBigEnough); // true
Arrow functions fornecem sintaxe mais curta para o mesmo teste.
[12, 5, 8, 130, 44].every((elem) => elem >= 10); // false
[12, 54, 18, 130, 44].every((elem) => elem >= 10); // true
every foi adicionado ao padro ECMA-262 na 5 edio; como tal, pode no estar presente em outras implementaes do padro. Voc pode contornar isso adicionando o seguinte cdigo no comeo dos seus scripts, permitindo o uso de every em implementaes que no o suportam nativamente. Esse algoritimo exatamente o mesmo especificado no ECMA-262, 5 edio, assumindo que Object e TypeError tem os seus valores originais e que callbackfn.call retorna o valor original de Function.prototype.call
if (!Array.prototype.every) {
Array.prototype.every = function (callbackfn, thisArg) {
"use strict";
var T, k;
if (this == null) {
throw new TypeError("this is null or not defined");
}
// 1. Let O be the result of calling ToObject passing the this
// value as the argument.
var O = Object(this);
// 2. Let lenValue be the result of calling the Get internal method
// of O with the argument "length".
// 3. Let len be ToUint32(lenValue).
var len = O.length >>> 0;
// 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
if (typeof callbackfn !== "function") {
throw new TypeError();
}
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (arguments.length > 1) {
T = thisArg;
}
// 6. Let k be 0.
k = 0;
// 7. Repeat, while k < len
while (k < len) {
var kValue;
// a. Let Pk be ToString(k).
// This is implicit for LHS operands of the in operator
// b. Let kPresent be the result of calling the HasProperty internal
// method of O with argument Pk.
// This step can be combined with c
// c. If kPresent is true, then
if (k in O) {
// i. Let kValue be the result of calling the Get internal method
// of O with argument Pk.
kValue = O[k];
// ii. Let testResult be the result of calling the Call internal method
// of callbackfn with T as the this value and argument list
// containing kValue, k, and O.
var testResult = callbackfn.call(T, kValue, k, O);
// iii. If ToBoolean(testResult) is false, return false.
if (!testResult) {
return false;
}
}
k++;
}
return true;
};
}
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-array.prototype.every |
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 |