How to access first element of JSON object array?

前端 未结 6 915
谎友^
谎友^ 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:02

    var req = { mandrill_events: '[{"event":"inbound","ts":1426249238}]' }
    
    console.log(Object.keys(req)[0]);
    

    Make any Object array (req), then simply do Object.keys(req)[0] to pick the first key in the Object array.

提交回复
热议问题