0

in json file,

Const = 
[{
    "id": "001",
    "name": "The Boys",
    "date": "2022",
    "genre": "Comedy",
    "type": "series"
}, {
    "id": "002",
    "name": "Money Heist",
    "date": "2020",
    "genre": "Action",
    "type": "series"
}, {
    "id": "003",
    "name": "John Wick",
    "date": "2022",
    "genre": "Action",
    "type": "movie"
}

I want to only display only one particular type. For instance, I don't want to display all files but only "type": "series" on my page without showing the others

Thanks for the help

DCR
  • 14,737
  • 12
  • 52
  • 115
Kobs
  • 1
  • 1
  • Does this answer your question? [How to filter object array based on attributes?](https://stackoverflow.com/questions/2722159/how-to-filter-object-array-based-on-attributes) – DCR Jun 18 '23 at 17:07

2 Answers2

0

here's the old school way to do this. >Look into the js filter() function

Const = 
[{
    "id": "001",
    "name": "The Boys",
    "date": "2022",
    "genre": "Comedy",
    "type": "series"
}, {
    "id": "002",
    "name": "Money Heist",
    "date": "2020",
    "genre": "Action",
    "type": "series"
}, {
    "id": "003",
    "name": "John Wick",
    "date": "2022",
    "genre": "Action",
    "type": "movie"
}]

cnt = Const.length;
for (i = 0; i < cnt; i++){
  if (Const[i]['type'] == "series"){
     console.log(Const[i]['id'])
   }
}
DCR
  • 14,737
  • 12
  • 52
  • 115
0

const data = [{
    "id": "001",
    "name": "The Boys",
    "date": "2022",
    "genre": "Comedy",
    "type": "series"
}, {
    "id": "002",
    "name": "Money Heist",
    "date": "2020",
    "genre": "Action",
    "type": "series"
}, {
    "id": "003",
    "name": "John Wick",
    "date": "2022",
    "genre": "Action",
    "type": "movie"
}];

const filteredData = data.filter(item => item.type === "series");
console.log(filteredData);
Shanu
  • 124
  • 4