0.0.3 • Published 4 years ago
jquery-reduce-object v0.0.3
ReduceObject - jQuery Plugin
Plain JavaScript objects reduce as known from the Array.prototype
Release with Dependencies !!!
If you include the jquery.reduce-object.min.js
only, be sure jQuery is part of your Project.
You will get it here:
Install - Demo
- Download
npm install
Run - Demo
node server.js
- Open your browser at
localhost:1234
API
var result = $.reduceObject(obj, callback, acc);
The reduceObject
function takes following arguments:
obj: {Object} -> the object to reduce
callback: {function} -> the function to reduce with
acc: {*} -> the initial value given the first iteration as 'dest' argument
The callback
function receives following arguments:
dest -> previous value
curr -> actual value in iteration
key -> actual key in iteration
obj -> the original object
Usage
- Include
jquery.reduce-object.min.js
into your Project
var objA = {
keyA = { value: 2 },
keyB = { value: 9 }
};
var result = $.reduceObject(objA, function(dest, curr, key, obj) {
dest += curr;
return dest;
}, { value: 31 });
console.log(result);
// { value: 42 }
Contributors
- Patrick Gräf - graef685@googlemail.com