Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript object filter

function objectFilter = (obj, predicate) => 
    Object.keys(obj)
          .filter( key => predicate(obj[key]) )
          .reduce( (res, key) => (res[key] = obj[key], res), {} );

// Example use:
var scores = {
    John: 2, Sarah: 3, Janet: 1
};

var filtered = objectFilter(scores, num => num > 1); 
console.log(filtered);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #object #filter
ADD COMMENT
Topic
Name
9+3 =