Storing items of an array depending on another value

后端 未结 2 1580
遥遥无期
遥遥无期 2021-01-20 16:37

I have an array called catalogue which holds 4 items:

packageid, dataid , categoryid and datapackage.

What I want to do is push into the array datai

2条回答
  •  广开言路
    2021-01-20 16:55

    Use the filter function to filter the result and map to get the ids:

    var dataids = (
       categoryBtnFilter==0 && packageBtnFilter==0
       ? catalogue
       : catalogue.filter(function(i) {
           return i.categoryid=categoryBtnFilter && i.packageid==packageBtnFilter
       })
    ).map(function(i){return i.dataid});
    

提交回复
热议问题