jquery-reduce-object

0.0.3 • Public • Published

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

Package Sidebar

Install

npm i jquery-reduce-object

Weekly Downloads

0

Version

0.0.3

License

GPL

Unpacked Size

136 kB

Total Files

9

Last publish

Collaborators

  • graef685