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

group by property javascript use reduce

group by property javascript use reduce

Kiểm tra định dạng email bằng Javascript

Kiểm tra định dạng email bằng Javascript

Await in a for loop

How to Await in a for loop

Converting Object to an Array

Converting Object to an Array

Merge Array

How to combine two sorted arrays into one? We can do this easily with the spread operator.