I need to filter an array of objects, like this:
var models = [
{
"family": "Applique",
"power":"8",
"volt":"12",
"color":"4100",
"type":"E27",
"ip":"20",
"dimensions":"230x92"
},
{
"family": "Lanterne",
"power":"20",
"volt":"230",
"color":"2700",
"type":"R7S",
"ip":"44",
"dimensions":"230x92"
},
{
"family": "Applique",
"power":"50",
"volt":"230",
"color":"",
"type":"GU10",
"ip":"20",
"dimensions":"227x227"
}
]
Based on a object like this:
var filter = {
"family":[
"Applique", "Faretto", "Lanterne"
],
"power":{
"less":[
"30"
],
"greater":[
],
"equal":[
]
},
"volt":[
"12", "230"
],
"color":[
],
"type":[
],
"ip":[
"20"
]
"dimensions":[
],
}
So, in this case, the result could be:
{
"family": "Applique",
"power":"8",
"volt":"12",
"color":"4100",
"type":"E27",
"ip":"20",
"dimensions":"230x92"
}
I've already read this other link: How to filter an array/object by checking multiple values, but I can not seem to adapt it to my case.
Thanks in advance!
EDIT: The condition on "power" property is not requested now
EDIT 2: Sorry, I've forgot to indicate that filter object can have multiple values for single property, like this:
var filter = {
"family":[
"Applique", "Faretto", "Lanterne"
],
...
"volt":[
"12", "230"
],
...
}