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

How to reverse an Array?

Reversing an array in JS is really simple with the standard array method. Like below

How to use the spread operator to flatten array of objects in javascript

How to use the spread operator to flatten array of objects in javascript

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).

Remove item in array javascript es6

Những bạn nào mà đã sử dụng ES6 một thời gian rồi thì có thể sử dụng method array.filter()

Lodash sort - Test performance with native js

Lodash sort - Bài viết ngắn gọn muốn đưa ra con số sau khi test về Lodash và Native js. Đây chỉ là check trên phương diện cá nhân...