can-util
Version:
Common utilities for CanJS projects
24 lines (17 loc) • 1 kB
Markdown
object data structure. Array-Like data structures are iterated by their numerical index. Objects are iterated by their named properties, i.e. in each stage of iteration the each function emits the key and its corresponding value.
{Object|ArrayLike} [elements] the object or Array-Like elements to iterate over
{function(element, key, elements)} [callback] the function that would be executed in each iteration
{Object} [context] the context object
{Object|ArrayLike} the original elements
```js
import each from "can-util/js/each/each";
each( [ 2, 1, 0 ], function( i ) {
console.log( this[ i ] );
}, [ 4, 5, 6 ] ); // -> 6 \n 5 \n 4
each( { foo: "bar", abc: "xyz" }, function( val, key ) {
console.log( key + ": " + val );
} ); // -> "foo: bar" \n "abc: xyz"
```
{function} can-util/js/each/each each
can-util/js
`each(elements, callback, context)`
A generic iterator function that can be used to iterate over both Array-Like and