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

175
Views
How to access array within an object? (Javascript)

Here is my object in a map function:

element: {2021-12-03: Array(12)}

How to I access the Array?

I've tried this:

element.date

But I get 'undefined'

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

0

To access properties of an object where the property name contains problematic characters like e.g. ., (), #, -, +, * , / or (space), use the square bracket [] notation and pass in the name of the property as a string:

element['2021-12-03'] // returns your array
about 4 years ago · Juan Pablo Isaza Report

0

I'd recommend restructuring your element such that:

element: {
   date: '2021-12-03',
   items: [....] // Array(12)....
}

then if you had something like an array of element you could find a specific date via:

my_element = elements.find(x => x.date === '2021-12-03')
about 4 years ago · Juan Pablo Isaza Report

0

You can restructure as @iamaword said. like this:

let data = {'2021-12-03': [1,2,3,4], '2021-11-03': [5,6,7,8]}

let elements = Object.entries(data).map(item => {
  return {date: item[0], items: item[1]} // Depends on you.
});

elements.forEach(element => {
 console.log(`${element.date}:${JSON.stringify(element.items)}`);
});

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!