-1

I am using Node.js and superagent for testing my server implementation. Using Superagent GET request is send and POSITIVE response is received using below CODE. My usecase to get and log only "id" (OUTPUT) value from the response message. How to extract "id" value from the response.

message Format: json

My Superagent CODE:

request.get(MyURL).then(res res => { 

 data = JSON.parse(res.text);

console.log(data);})

OUTPUT:

{ data:
   [ { id: '35132df0-fa8c-42ec-80d7',
       name: 'name1',
       uri: '/xxxx/yyyy/35132df0-fa8c-42ec-80d7' } ],
  status: 'ok' 
}

Thank you

Yared
  • 2,206
  • 1
  • 21
  • 30
kar
  • 2,505
  • 9
  • 30
  • 32

1 Answers1

1

let foo = { data: [ { id: '35132df0-fa8c-42ec-80d7', name: 'name1', uri: '/xxxx/yyyy/35132df0-fa8c-42ec-80d7' } ], status: 'ok' }

console.log(foo.data[0].id)