Kann mir bitte jemand helfen zu verstehen, was hier los ist?array.push ist keine Funktion - bei der Arbeit mit reduzieren
let firstArray = [];
firstArray.push(1);
firstArray.push(1);
firstArray.push(1);
console.log("firstArray", firstArray); // result [ 1, 1, 1 ] - as expected.
let secondArray = [1, 2, 3].reduce((acc, item) => {
console.log("acc", acc);
console.log("typeof acc", typeof acc);
// on first passing, the accumulator (acc) is Array[] == object.
// on the second passing the acc == number.
// but why?
/// i expect to get [1,1,1] as my secondArray.
return acc.push(1);
}, []);
console.log("secondArray", secondArray);
stürzt das Programm mit „acc.push ist keine Funktion“
Und Inspektion der erste protokolliert accumulator
zeigt, dass wir die Push-Methode haben - es ist eine echte Funktion:
'return acc.concat (item);' – fubar
Does 'push' das Element geschoben zurückkehren? Versuchen Sie, auf eine separate Zeile zu drücken, und geben Sie dann zurück. – Carcigenicate