I have this long list of array and I want to filter the object return by id. For example, I want to get objects with the same id, in this case object at index 0 and index 2. How can i achieve this? I have tried the for loop method but it's not going anywhere
var arr = [
{
"name": "David",
"last_updated": "2021-04-12 15:42:51",
"id": "175",
"class": "CLASS 2019",
"stops": [
{
"total": "29",
"graduated": "1900"
},
],
},
{
"name": "Cameron",
"last_updated": "2021-04-12 15:42:51",
"id": "180",
"class": "CLASS 2021",
"stops": [
{
"total": "40",
"graduated": "2500"
},
],
},
{
"name": "Rose",
"last_updated": "2021-04-12 15:42:51",
"id": "175",
"class": "CLASS 2008",
"stops": [
{
"total": "50",
"graduated": "1000"
},
],
},
This is a short snippet that I have in mind and tried. I'm aware that it doesn't make sense hence why I'm asking here. Any explanations and workarounds is very much appreciated
for(let i=0; i<arr.length; i++) {
if(arr[i].id === arr[i].id) {
console.log(arr[i])
}
}