Skip to content

Known JavaScript Array Reduce For Plain JavaScript Objects

License

Notifications You must be signed in to change notification settings

graef685/ReduceObject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Known JavaScript Array Reduce For Plain JavaScript Objects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published