I have an array full of objects:
var myArray = [{ "user": "anton" }, { "user": "joe" }];
I would now like to wrap the array into a Underscore Collection object so that I can nativly use underscore’s collection methods (remove, add) with it:
myArray = _(myArray); // this only add object methods
myArray.add({ "user": "paul" });
So how do I wrap an array with underscore to use underscores collection methods
Generally underscore api doesn’t wrap array or object. just passing it first argument.
ex)
But chain (
_.chain(obj)) Returns a wrapped object. Calling methods on this object will continue to return wrapped objects until value is used.check underscore api : http://underscorejs.org/#