-1

Why is this simple example returning an empty array?

const arr = [1, 2];
const result = arr.reduce((list, val) => {
  list.push[val];
  return list;
}, []);

console.log(result);
LongHike
  • 3,362
  • 3
  • 31
  • 59

1 Answers1

0

You are using Array.prototype.push in the wrong way.

const arr = [1, 2];
const result = arr.reduce((list, val) => {
  list.push(val);
  return list;
}, []);

console.log(result);
Akshay Bande
  • 2,332
  • 2
  • 10
  • 24