Skip to content

Instantly share code, notes, and snippets.

@phiggins42
Created October 6, 2010 14:31
Show Gist options
  • Save phiggins42/613435 to your computer and use it in GitHub Desktop.
Save phiggins42/613435 to your computer and use it in GitHub Desktop.
dojo.filterObject = function(obj, filterFn, context){
var ret = {}; context = context || window;
for(var i in obj){
if(filterFn.call(context, obj[i], i, obj)){
ret[i] = obj[i];
}
}
return ret;
}
@neonstalwart
Copy link

@phiggins42
Copy link
Author

yah it's like forEach for objects, but is actually more like array.filter in that the return of the callback is used to determine if the item should be included in the copy.

@neonstalwart
Copy link

sorry... the link was to filterIn but i wrote forIn - i meant filterIn which works as you say, i blame jetlag :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment