Node.js examples for Array:Array Value
Group value in array
Array.prototype.groupBy = function (predicate) { var results = []; var items = this; var keys = {}, index = 0; for (var i = 0; i < items.length; i++) { var selector; if (typeof predicate === "string") { selector = items[i][predicate]; } else {/*from www.j a va 2 s.c om*/ selector = predicate(items[i]); } if (keys[selector] === undefined) { keys[selector] = index++; results.push({ key: selector, value: [items[i]] }); } else { results[keys[selector]].value.push(items[i]); } } return results; };