Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
Do arrays in JavaScript have key-attributes?

I was stumbling around in JavaScript and was wondering why my tests were still working, although I changed a constant from an Object to a Variable.

I'm aware that Object properties can be accessed by key-values, e.g.

const object = {};
object['keyValue'] = 'property';

// creates this object
{ keyValue: 'property' };

I thought that this was only possible for Objects, however, I accidentally executed the following code:

const array = [];
array['maybeKeyValue'] = { keyValue: 'property'};

// this created the following array
[ship: {keyValue: 'property'}]

// i can also access the object in the array
const obj = array['ship'];
// returns the created object

I also noticed that the array.length is 0 and that array.entries() does not create an valid iterator, which is strange for me. What is happening here? Is this a valid alternative to storing keys with values in an Object?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda