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

128
Views
I can't access any properties in my jQuery array of objects

I am creating an array of objects, I need to access the properties in this array of objects and yet, when I try to do this I get get an error of 'undefined'. I've searched for this problem but I can't find anything that I've done that would prevent it from working.

To start I define and empty array.

var gantt_data_array = [];

I then access my data using ajax from a controller. On success, I iterate over the results and push the required object into the array.

var get_data = $.ajax({    
    url: "/Gantt/Read_Gantt",    
    success: function (result) {
        $.each(result, function (d, v) {   
            gantt_data_array.push({
                "startDate": v.Commencement_Date,
                "endDate": v.End_Date,
                "taskName": v.Vessel_Name,
                "status": v.Firm_Status
            });
        })
    },
    error: function (xhr, status, error) {
        console.log("error")
    }
});

I then try to access a property for use in other places in the following manner, which returns as undefined:

console.log(gantt_data_array['startDate'])

I checked the array for data by logging out the array itself

console.log(gantt_data_array)

Which shows the data in the expected format

[]
    0: { startDate: ...something, endDate: ...something, taskName: ...something, status: ...something }
    1: { startDate: ...something, endDate: ...something, taskName: ...something, status: ...something }

When I log the length of the array however console.log(gantt_data_array.length) it returns 0. Am I pushing this correctly? Have I made a simple mistake? I can't see what would be causing this problem.

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!