group by property javascript use reduce

reduce,es6,tipjs

Group by property javascript use reduce

const result = [
  {subject: 'blog javascript', marks: 41},
  {subject: 'anonystick.com', marks: 59},
  {subject: 'blog developers', marks: 36},
  {subject: 'blog programmers', marks: 90},
  {subject: 'medium.com', marks: 64},
];
let initialValue = {
  pass: [], 
  fail: []
}
const groupedResult = result.reduce((accumulator, current) => {
  (current.marks >= 50) ? accumulator.pass.push(current) : accumulator.fail.push(current);
  return accumulator;
}, initialValue);
console.log(groupedResult);

Có thể bạn đã miss một số snippets code

Copy a string to the clipboard

Copy a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).

10 mẹo sử dụng array và object trong javascript

10 mẹo sử dụng array và object trong javascript

Object.keys và Object.getOwnPropertyNames

Object.keys và Object.getOwnPropertyNames

using async/await to catch errors

JavaScript: async/await with forEach

JavaScript: async/await with forEach()