I am getting this result from my API :
But any with the same id (like the last 2) i would like to be grouped in an object so there would be only 3 items in the array (0,1,2) and the last one would be nested within the last one because it has a duplicate ID. It is ordered in the correct format from the SQL so i would like it to keep it's order.
There could be up to 50 with the same id that might need to nest, i tried using an array and the key but cant get the desired result
if(data.length > 0){
console.log(value);
try{
if(value.id == s[key - 1].id){
console.log("match");
s.push(value);
} else {
orderobj.push(s);
}
} catch(ex){}
console.log(orderobj);
}

idis the primary key, if you are allowing duplicates; why can't you just group these the way they are grouped in the database?