Javascript Advanced Methods. Could someone please tell me what is reduce actually used for ? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

Javascript Advanced Methods. Could someone please tell me what is reduce actually used for ?

7th Jun 2019, 7:35 AM
Sudarshan Rai
Sudarshan Rai - avatar
2 Respostas
+ 1
it does what it says. it reduces the array. for eg when you want the sum of the elements of an array, you can use the reduce method to do so. var arr=[1,3,4]; var sum=arr.reduce(function(accumulator, currentValue) { return accumulator+currentValue; }); alert(sum); // 8
7th Jun 2019, 7:59 AM
Farry
Farry - avatar
0
Reduce an array to a single value or another array, object.
7th Jun 2019, 8:57 AM
CalviÕ²
CalviÕ² - avatar