Storing items of an array depending on another value

后端 未结 2 1576
遥遥无期
遥遥无期 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});
    
    0 讨论(0)
  • 2021-01-20 17:10

    I assume your condition should be something like

    if ((packageBtnFilter == 0 && categoryBtnFilter == 0) || this.packageid == packageBtnFilter || this.packageid == categoryBtnFilter) dataids.push(this.dataid);
    
    0 讨论(0)
提交回复
热议问题