From the course: JavaScript: Arrays
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Single values with reduce - JavaScript Tutorial
From the course: JavaScript: Arrays
Single values with reduce
- [Instructor] Have you ever encountered an array of values that needed to be added up and reduced to a single value or a grand total? This is where the array method, reduce, can be helpful to do just that. One of the most powerful array methods available is reduce. For me, this array method has been more difficult to grasp because of its syntax. I typically have to look it up for this array method because it does operate a little bit differently than the other array methods we've discussed thus far. So what exactly does reduce do? Reduce executes a reducer function against each item in the array, returning a single value. The value returned is the accumulated value. You'll often see this used with numbers, although it can be used with strings as well to determine counts and frequency. Where things get a little bit more tricky is with the syntax. Reduce uses a slightly different syntax than what we're used to seeing.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.