This is my outcome from the server.
arrays=
[ 0:
{ Id: 1
, name: 'test1'
, parameters:
[ { name: 'application_instance', value: 'home', type: 'generic' }
, { name: 'application_name', value: 'initial', type: 'generic' }
, { name: 'application_role', value: 'disk_init_role', type: 'generic' }
, { name: 'customer_environment', value: 'development', type: 'generic' }
, { name: 'customer_name', value: 'guest', type: 'generic' }
] }
, 1:
{ Id: 2
, name: 'test2'
, parameters:
[ { name: 'application_instance', value: 'home', type: 'generic' }
, { name: 'application_name', value: 'disk_init', type: 'generic' }
, { name: 'application_role', value: 'initial', type: 'generic' }
, { name: 'customer_environment', value: 'development', type: 'generic' }
, { name: 'customer_name', value: 'guest', type: 'generic' }
] }
, 2:
{ Id: 3
, name: 'test3'
, parameters:
[ { name: 'application_instance', value: 'home', type: 'generic' }
, { name: 'application_name', value: 'initial', type: 'generic' }
, { name: 'application_role', value: 'initial', type: 'generic' }
, { name: 'customer_environment', value: 'development', type: 'generic' }
, { name: 'customer_name', value: 'guest', type: 'generic' }
] }
, 3:
{ Id: 4
, name: 'test4'
, parameters:
[ { name: 'application_instance', value: 'home', type: 'generic' }
, { name: 'application_name', value: 'initial', type: 'generic' }
, { name: 'application_role', value: 'disk_init_role', type: 'generic' }
, { name: 'customer_environment', value: 'development', type: 'generic' }
, { name: 'customer_name', value: 'guest', type: 'generic' }
] }
, 5:
{ Id: 5
, name: 'test5'
, parameters:
[ { name: 'application_instance', value: 'home', type: 'generic' }
, { name: 'application_name', value: 'initial_disk_init', type: 'generic' }
, { name: 'application_role', value: 'disk_initial', type: 'generic' }
, { name: 'customer_environment', value: 'development', type: 'generic' }
, { name: 'customer_name', value: 'guest', type: 'generic' }
]
}
]
And i need to filter it with multiple conditions.
filters = {
application_name: 'initial',
application_role: 'disk_init_role'
}
I made a function to filter the data but this works only with one condition
filterArray (array, filters) {
for (var [key, value] of Object.entries(filters)) {
const res = Object.values(array).filter(
item => item.parameters.some(param => param.name === `${key}` && param.value === `${value}`)
)
return results
}
}
What is the best way to loop through the array so both contions (filters) are met? The outcome needs to be only id 1 and 4 and thats needs to be in a return results array.