How to access first element of JSON object array?

前端 未结 6 917
谎友^
谎友^ 2021-01-03 21:10

I exptect that mandrill_events only contains one object. How do I access its event-property?

var req = { mandrill_events: \'[{\"event\":\"inboun         


        
6条回答
  •  迷失自我
    2021-01-03 22:03

    Assuming thant the content of mandrill_events is an object (not a string), you can also use shift() function:

    var req = { mandrill_events: [{"event":"inbound","ts":1426249238}] };
    var event-property = req.mandrill_events.shift().event;
    

提交回复
热议问题