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

103
Views
Acessing an object propery with array bracket notation

I want to access a specific property in an object. Using an array for example

let array = ["tom","tony", "jerry"];

let object = {
  tony: "Brother", 
  tom: "Uncle", 
  jerry: "Cousin", 
};

object.array[1];

I'm trying to access object.tony but what happens is that it returns object."tony" instead.

The problem is that it returns it as a string so it causes an error.

Is it possible to return array[1] not as a string?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In object.array[1], JS will think your looking for array inside object, which does not exist. If an array was in the object, it would work:

let object = {
    array: ["tom", "tony", "jerry"],
    // some other stuff...
};
console.log(object.array[1]);

You can use brackets instead:

object[array[1]];

Example:

let array = ["tom","tony", "jerry"];
let object = { tony: "Brother", tom: "Uncle", jerry: "Cousin", };
console.log(object[array[1]]);

about 4 years ago · Juan Pablo Isaza Report
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!