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

lỗi access-control-allow-origin và cách khắc phục

lỗi access-control-allow-origin và cách khắc phục trong express, nodejs

Đếm số phần tử trong mảng JavaScript

Đếm số lần xuất hiện của các phần tử trong mảng JavaScript

Rest Operator for Objects

Now we can use rest on the properties of an Object. It allows us to explicitly extract certain named variables, and assign any uncalled variables into a catchall Object.

How to reverse an Array?

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

Promise + gì

promise + gì