skip to Main Content

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

2

Answers


  1. 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'])
       }
    }
    Login or Signup to reply.
  2. 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);
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search