Looking to extract information from a URL that contains JSON data for multiple objects, I came up with the following code:
static fetchObj(){
fetch("http://localhost:1337/objects")
.then(callback => {
return callback.json();
})
.then(data => {
console.log(data);
});
}
This allows me to successfully retrieve and output the necessary information.
Next, I need to utilize this data in another function that searches for specific objects based on their ID:
static fetchObjById(id) {
MyClass.fetchObj()
.then(
for(var i=0; i<data.id.length; i++){
if(data[i].id == id)
console.log("found");
else
console.log("not found");
}
}
However, despite attempting various methods, I have been unable to make it work. Any help or advice would be greatly appreciated!