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

arry to object using reduce

const posts = [
    {id: 1, category: "frontend", title: "All About That Sass"},
    {id: 2, category: "backend", title: "Beam me up, Scotty: Apache Beam tips"},
    {id: 3, category: "frontend", title: "Sanitizing HTML: Going antibactirial on XSS attacks"}
];

const categoryPosts = posts.reduce((acc, post) => {
    let {id, category} = post;
    return {...acc, [category]: [...(acc[category] || []), id]};
}, {});
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

PREVIOUS NEXT
Code Example
Javascript :: React 18 to 17 
Javascript :: parse integer in javascript 
Javascript :: sequelize mariadb example 
Javascript :: javascript fill circle with color 
Javascript :: short if statements in javascript 
Javascript :: mongoose db connect 
Javascript :: javascript capitalize all letters 
Javascript :: Creating URL Search Parameters From An Array 
Javascript :: how to add to an array js 
Javascript :: discord.js edit embed message 
Javascript :: addeventlistener javascript 
Javascript :: axios request and response intercepters 
Javascript :: repeat a function javascript 
Javascript :: mongoose deprecation warning 
Javascript :: ** javascript 
Javascript :: jquery find element before 
Javascript :: javascript date format dd-mm-yyyy 
Javascript :: razor list to js array 
Javascript :: jest run specific test 
Javascript :: jspdf create table 
Javascript :: javascript Strict Mode in Function 
Javascript :: THE REDUCE() METHOD IN JAVASCRIPT 
Javascript :: object to map javascript 
Javascript :: edit external json file in javascript 
Javascript :: string splice javascript 
Javascript :: js mysql date format and dmy format 
Javascript :: javascript copy value to clipboard 
Javascript :: creating a module with lazy loading in angular 9 
Javascript :: how to generate a new page component in angular 
Javascript :: run javascript in html 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =