There is such a code that filters the array by the specified parameters and outputs the result to the console. In this case, the code samples by the color value with the red property and the number with the property 10 in the objects that fill the array.
The code works, but the problem will arise, for example, when there are more than two check-boxes. I tried to use the cycle, but nothing happened. Help to modify the code so that there is no need to list inputs by index, i.e. that there was one function that would perform a common task.
var colorsAndNumbers = [{ color: 'red', number: 10 }, { color: 'yellow', number: 10 }, { color: 'red', number: 5 }, { color: 'black', number: 5 }, { color: 'red', number: 5 } ] var form = document.querySelector('.filters'); var inputs = Array.from(document.querySelectorAll('.filters input')); var formChangeHandler = function() { var newList = colorsAndNumbers.filter(function(item) { if (inputs[0].checked) { return item.color === inputs[0].value; } else { return item; } }). filter(function(item) { if (inputs[1].checked) { return item.number === +inputs[1].value; } else { return item; } }); console.log(newList); } form.addEventListener('change', formChangeHandler); <div class="main"> <form action="#" class="filters"> <input type="checkbox" name="features" value="red" id="color"> <label class="feature" for="color">Color Red</label> <input type="checkbox" name="features" value="10" id="number"> <label for="number">Number 10</label> </form> </div>