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