1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How do I get json data from this array

Discussion in 'JavaScript' started by ketting00, Jan 11, 2020.

  1. #1
    Hi Guy,

    I've this simple data and I want to use it:
    [ {id: 1, name: 'John Smith' } ]
    Code (markup):
    So how do I get the id or the name out of this set of data.
    SEMrush
    Thank you,
     
    ketting00, Jan 11, 2020 IP
    SEMrush
  2. ketting00

    ketting00 Well-Known Member

    Messages:
    726
    Likes Received:
    20
    Best Answers:
    3
    Trophy Points:
    118
    #2
    Ok, I get it.
    var data = [ {id: 1, name: 'John Smith' } ];
    console.log(data[0].name);
    
    Code (markup):
     
    ketting00, Jan 11, 2020 IP
    scu8a likes this.
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,147
    Likes Received:
    1,702
    Best Answers:
    239
    Trophy Points:
    515
    #3
    The outer "mandatory" array of JSON often throws people like that.
     
    deathshadow, Jan 12, 2020 IP