Hi I have to filter an array based on some conditions. I want to avoid having to write out a bunch if statements. My code below shows pretty much what I want to accomplish. The * you see is just me trying to say filter to any (like a wild card). Do you have any idea how I can best accomplish my goal? Thank you
let x =eq.filter(eq => eq.empid == selectedTech === 'ALL Techs'? '*' : selectedTech
&& eq.code == selectedStatus === 'ALL Statuses'? '*' : selectedStatus
&& eq.cellnum == phn === '' ? '*': phn
&& eq.jobid == jobid === '' ? '*': jobid
);
Example of the object:
var eq = [{
empid: 1,
jobid: 27,
code: "Not Started",
cellnum: "3058888888",
brand: "GK",
model: "X500"
}, {
empid: 1,
jobid: 33,
code: "Not Started",
cellnum: "3058888899",
brand: "Mackie",
model: "X500"
}, {
empid: 2,
jobid: 35,
code: "In Progress",
cellnum: "3058888877",
brand: "Samson",
model: "X522"
}, {
empid: 1,
jobid: 36,
code: "Not Started",
cellnum: "3058888866",
brand: "Mackie",
model: "X467"
}, {
empid: 1,
jobid: 37,
code: "In Progress",
cellnum: "3058888800",
brand: "Fender",
model: "X500"
}]
}
eq.jobid == jobid === '' ? '*': jobid?