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

321
Views
Javascript Dot Notation = Undefined

Dot notation allows for accessing objects with a '.' Cannot figure out why this is happening. I have the following success function, as part of a jQuery $.ajax function.

success: function(data){
  console.log('data = ' + data);
  console.log('data.president = ' + data.president);
  console.log('data.adviser = ' + data.adviser);
}

This, oddly, results in the following browser log:

data = {"president":1,"adviser":1}
data.president = undefined
data.adviser = undefined

I must be missing something painfully obvious. Can somebody enlighten me?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

The data would have to be an Object to be accessed by a dot .. It's a string now. You need to parse it using for example:

data = JSON.parse(data);
over 4 years ago · Santiago Trujillo Report

0

Set dataType: "json" as ajax option so jQuery would parse your string data to javascript object

over 4 years ago · Santiago Trujillo Report

0

You define the data elements has strings, attributes of an object need to be declared without quotes, like this:

data = {president:1,adviser:1}

in that case you got the expected result

data.president = 1
data.adviser = 1
over 4 years ago · Santiago Trujillo 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!