Hi I am very new to JSON and API, and working on an API in which I am getting value in an array eg.
{
id: 0,
text: "one"
}
{
id: 1,
text: "two"
}
{
id: 2,
text: "three"
}
I want the value of only of an array where id=0 and i don't know how to sort array in JSON to achieve this, I used ajax to fetch this value
async function getDataFromId() {
let url = 'API_URL';
let Qid = 1;
let result;
try {
result = await jQuery.ajax({
url: url,
type: 'GET',
contentType: 'application/json',
});
result = result.sort((a, b) => a.id- b.id);
console.log(result)
}catch (error) {
console.error(error);
}
}
id=0? Wouldn't filter it be enough?var new_array = result.filter(function(i){return i.id == 0})