Reputation: 829
I send a GET request to the client and objects in the body are returned to me. Now I need to work with one specific object, for example, display the name of the object under ID 3. How can I do this?
const requestURL = '/coffee/all'
const xhr = new XMLHttpRequest();
xhr.open('GET', requestURL)
xhr.onload = () => {
var datas = JSON.parse(xhr.response);
console.log(datas)
}
xhr.send()
Upvotes: 0
Views: 1412
Reputation: 36
const requestURL = '/coffee/all'
const xhr = new XMLHttpRequest();
xhr.open('GET', requestURL)
xhr.onload = () => {
var datas = JSON.parse(xhr.response);
console.log(datas.find(item => item.id === 3).name)
}
xhr.send()
Upvotes: 2