Does Dojo have a method similar to jQuery's each()
that allows you to pass an object to iterate over? jQuery.each()
allows you to pass either an array or an object. In the latter case, the callback function receives both a key and the value. Is there something that allows you to do this in Dojo?
Looks like you are looking for dojox.lang.functional.object.forIn
.
There's no actual documentation page in dojo reference, only a small example in article Functional fun in JavaScript with Dojo:
Module dojox.lang.functional.object defines important object helpers:
df.forIn(object, callback[, thisObject])
If you have something against using that module you can also easily make your own variant:
function objEach(obj, f, scope){
for(var key in obj){
if(obj.hasOwnProperty(key)){
f.call(scope, obj[key], key);
}
}
}
For arrays there is already dojo.forEach() in the base library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With