each

  • function
can.Observe.prototype.each  

Call a function on each property of an Observe.

observe.each( callback(item, propName ) )

each iterates through the Observe, calling a function for each property value and key.

Parameters

  1. callback {function(item, propName)}

    the function to call for each property The value and key of each property will be passed as the first and second arguments, respectively, to the callback. If the callback returns false, the loop will stop.

Returns

{can.Observe}

this Observe, for chaining

var names = [];
new can.Observe({a: 'Alice', b: 'Bob', e: 'Eve'}).each(function(value, key) {
    names.push(value);
});

names; // ['Alice', 'Bob', 'Eve']

names = [];
new can.Observe({a: 'Alice', b: 'Bob', e: 'Eve'}).each(function(value, key) {
    names.push(value);
    if(key === 'b') {
        return false;
    }
});

names; // ['Alice', 'Bob']