Filter JavaScript Array with Multiple Dropdown

Hi, I’ve two dropdown which I use to filter the dataset. Following code I use to filter the dataset & working fine.

filter = filter.eq("_owner","expenseFor", filter1)).and(filter.contains("type", filter2))

I’ve another result which I stored in array with name “arryo”. Object is shown below:

0: {...}
type: "Debit"
principal: 15000
days: 1
interest: -4.75
expfo: "Ration"

1: {...}
type: "Credit"
principal: 3000
days: 1
interest: 1
expfo: "pesticides"

Now, I want to filter this array using dropdown1 → expfo & dropdown 2 → type
I’ve tried with four combination of two dropdown array filter is working fine. But in case I increase the dropdown then it’s hard to write each & every case. Please help me.

First, I tried to filter using both dropdowns condition but failed because intially dropdown value is “” which make array empty too. So, I try something this again but this is entering only in if loop. Besides this, I’ve tried not of methods but failed.

let doo = arryo.filter(function (currentElement) {
 if ($w('#dropdown1').value !== "" || $w('#dropdown1').value !== undefined || $w('#dropdown1').value !== null) {
                            console.log("Entered in IF");
                            return currentElement.expfo === $w('#dropdown1').value;
                            console.log("Entered in Else");
                            return currentElement;

Approach: - Now, my approach is to filter the array with dropdown1. If dropdown selected then items will be filtered and then check this with dropdown2 using filter. If any of the dropdown value is not available then return the entire array as it is.

I’m unable to implement my approach. If you help me with this please reply. Also, if you’ve better code then please let me know.

Thank you :slight_smile:


  1. if($w(‘#dropdown1’).value) is what you need. No need to check for every type of truthy condition.

  2. return currentElement.expfo === $w(‘#dropdown1’).value will return true or false . Is that what you need?

  1. Dropdown1 is for expense category “expfo” in array. Value of dorpdown1 filter the array. But initially, on page load dropdown value is not selected that’s why it return only empty array.

  2. I need the filtered array to find the sum of interest value in array according to dropdown values.