| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Array/length | [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.
A propriedade length representa um inteiro de 32-bit sem sinal, que especifca o nmero de elementos em um array.
Property attributes of Array.prototype.length | |
|---|---|
| Writable | yes |
| Enumerable | no |
| Configurable | no |
arr.length
O valor da propriedade length um inteiro com um sinal positivo e valor menor que 2 elevado na 32 potncia(232).
Voc pode setar o a propriedade length para truncar um array a qualquer momento. Quando voc extende um array mudando sua propriedade length, o numero de elementos atuais no incrementado; por exemplo, se voc setar o tamanho para 3 quando ele atualmente 2, o array continua somente com 2 elementos. Assim, a propriedade length no diz nada sobre o tamanho de valores definidos no array. Veja tambm Relacionamento entre length e propriedades numricas.
No exemplo a seguir numbers iterado considerando a propriedade length para ver quantos elementos ele tem. O valor de cada elemento recebe ento o dobro.
var numbers = [1, 2, 3, 4, 5];
for (var i = 0; i < numbers.length; i++) {
numbers[i] *= 2;
}
// numbers is now [2, 4, 6, 8, 10]
O exemplo a seguir encurta o array statesUS para um tamanho de 50 se o tamanho corrente for maior do que 50.
if (statesUS.length > 50) {
statesUS.length = 50;
}
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-properties-of-array-instances-length |
This page was last modified on 17 de dez. de 2024 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 |