Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!