Sololearn: Learn to Code
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 2
Or use array method, map const fruits2 = fruits.map(fruit => fruit ? fruit : "new fruit");
30th Apr 2022, 1:44 AM
Calviղ
Calviղ - avatar
0
reduce() reduce() loops through original array, and then returns a "result" (Not necessarily an array). reduce() accepts two parameters: 1. A reducer function 2. Initial Value For the reducer function, it accepts two to four parameter: 1. Accumulator 2. Each item of original array 3. (Optional) Index of the item in original array 4. (Optional) Original Array Demo: https://code.sololearn.com/cqHxL5WFU1PQ/?ref=app Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce
24th Apr 2022, 4:01 AM
Gordon
Gordon - avatar