Storing Items Of An Array Depending On Another Value
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 dataids all the dataids of items who
Solution 1:
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});
Solution 2:
I assume your condition should be something like
if ((packageBtnFilter == 0 && categoryBtnFilter == 0) || this.packageid == packageBtnFilter || this.packageid == categoryBtnFilter) dataids.push(this.dataid);
Post a Comment for "Storing Items Of An Array Depending On Another Value"