Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript reduce array of objects

var objs = [
  {name: "Peter", age: 35},
  {name: "John", age: 27},
  {name: "Jake", age: 28}
];

objs.reduce(function(accumulator, currentValue) {
  return accumulator + currentValue.age;
}, 0); // 35 + 27 + 28 = 90
Comment

array of obj to obj with reduce

const convertArrayToObject = (array, key) => {
  const initialValue = {};
  return array.reduce((obj, item) => {
    return {
      ...obj,
      [item[key]]: item,
    };
  }, initialValue);
};
Comment

reduce method in javascript array of bjects

var arr = [{x:1}, {x:2}, {x:4}];
arr.reduce(function (acc, obj) { return acc + obj.x; }, 0); // 7
console.log(arr);
Comment

reduce an array of objects into a single object

var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery datatable update row cell value 
Javascript :: why does javascript have hoisting 
Javascript :: kafka nodejs example 
Javascript :: import npm dotenv package 
Javascript :: connect mongodb using mongoose in node js 
Javascript :: check if array is empty javascript 
Javascript :: Setting axios base url dynamically 
Javascript :: selected text 
Javascript :: react video 
Javascript :: convert celsius to fahrenheit javascript 
Javascript :: change module name react native android studio 
Javascript :: regex look behind 
Javascript :: usehistory() hook 
Javascript :: array flatten 
Javascript :: .includes is not a function 
Javascript :: how to change size of button in react native 
Javascript :: discord.js set role permissions for all channels 
Javascript :: how to import in react js 
Javascript :: Max JavaScript Methods 
Javascript :: JavaScript Element fade out 
Javascript :: js promise 
Javascript :: name first letter uppercase 
Javascript :: JavaScript POSITIVE_INFINITY 
Javascript :: how to skip the execution or for loop using continue js 
Javascript :: javascript hoisting 
Javascript :: js if not undefined or null 
Javascript :: onclose modal bootstrap 
Javascript :: Add remove link dropzone 
Javascript :: get url from string javascript 
Javascript :: check for palindromes 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =