CKTIS / JavaScript
Array.prototype.some: existencia de algún elemento coincidente
some se detiene con el primer resultado truthy y comunica si coincidió un elemento existente.
Versión: ECMAScript 2026 draft; example target: Node.js 24.22.2
Sintaxis
array.some(callbackFn[, thisArg])array.some(callbackFn[, thisArg]) visita índices existentes en orden ascendente y llama a callbackFn(value, index, array). Devuelve true inmediatamente ante el primer resultado truthy; si no, false. Un array vacío produce false y los huecos se omiten.
La longitud se captura antes de la primera llamada: no visita adiciones posteriores fuera de ella y omite un índice eliminado a tiempo. thisArg proporciona this a una función normal, no a una flecha. El método no muta por sí mismo y es genérico para array-like. Un callback no invocable o receptor null o undefined lanza TypeError; los errores del callback se propagan.
Ejemplos
const visited = [];
const sparse = [, 3, 8, 10];
const found = sparse.some((value, index, array) => {
visited.push(index);
if (index === 1) array.push(12);
return value % 2 === 0;
});
console.log(found, visited.join(","), sparse.length);
console.log([].some(() => true));
const limit = { value: 5 };
console.log([2, 6].some(function (value) { return value > this.value; }, limit));Resultado
true 1,2 5 false true