#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    327
    Rep Power
    18

    Can't access data inside curly brackets


    I have some data passed to me as 'data' and when I do console.log(data.person) I see the returned structure as

    Person {
    first,'John',
    last,'Doe'
    }

    Now, Person is defined like this

    person:
    Person {
    first: 'John',
    last: 'Doe'
    }

    but when I do console.log(data.person.Person) I get an error of Person is undefined or possibly null if I'm misremembering. How do I access "first" value?
    Last edited by drhowarddrfine; March 15th, 2017 at 03:42 PM.
  2. #2
  3. Forgotten Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,013
    Rep Power
    9616
    What you're saying doesn't make sense.

    If the console.log(data.person) showed you a Person object then you should be doing data.person.first and data.person.last.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    327
    Rep Power
    18
    That's what the problem is! I forgot that it's an object! Too many things going on. Thanks

IMN logo majestic logo threadwatch logo seochat tools logo