I am working with an array that looks like this:
var arr =
[
{
"id":3,
"first_name":"Laila",
"last_name":"McCaine",
"gender":"female",
"populations":[{"population_name":"Heart failure"}, {"population_name":"AMI"}],
"score": 55.0
},
{
"id":5,
"first_name":"Riva",
"last_name":"Rontgen",
"gender":"female",
"populations":[{"population_name":"Pnumonia"}],
"score": 85.0
},
{
"id":8,
"first_name":"Emily",
"last_name":"Rosewood",
"gender":"female",
"populations":[],
"score": 25.0
}
];
Additionally, I have the following variables defined:
var score='';
var population='';
var status = '';
Now, I need to use the filter
function on the array with multiple conditions such as
Find records where the score
is less than 40, status
equals 1, and population_name
is "heart failure".
The challenge here is that these three variables are dynamic, and the filter should only be applied if their values are not empty.
How can I achieve this?