- Notifications
You must be signed in to change notification settings - Fork0
Known JavaScript Array Reduce For Plain JavaScript Objects
License
NotificationsYou must be signed in to change notification settings
graef685/ReduceObject
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Plain JavaScript objects reduce as known from the Array.prototype
If you include thejquery.reduce-object.min.js
only, be sure jQuery is part of your Project.
You will get it here:
- Download
npm install
node server.js
- Open your browser at
localhost:1234
varresult=$.reduceObject(obj,callback,acc);
ThereduceObject
function takes following arguments:
obj: {Object}-> the object to reducecallback: {function}-> the function to reduce withacc: {*}-> the initial value given the first iteration as 'dest' argument
Thecallback
function receives following arguments:
dest-> previous valuecurr-> actual valuein iterationkey-> actual keyin iterationobj-> the original object
- Include
jquery.reduce-object.min.js
into your Project
varobjA={ keyA={value:2}, keyB={value:9}};varresult=$.reduceObject(objA,function(dest,curr,key,obj){dest+=curr;returndest;},{value:31});console.log(result);// { value: 42 }
- Patrick Gräf -graef685@googlemail.com