Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to filter multiple values from a json api

const filters = {forSale: true, color: 'blue'}; 
const filteredArray = array.filter(item => {
    let result = true;
    for(let key in filters) {
        if (item[key] !== filters[key]){
            result = false;
            break;
        }
    }
    return result;
})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #filter #multiple #values #json #api
ADD COMMENT
Topic
Name
4+2 =