Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Array Iteration Methods Combining Array Methods Nested Data and Additional Exploration

Amandeep Pasricha
Amandeep Pasricha
14,932 Points

Did we need to specify the default value of the accumulator to be equal to "[]"?

For example, we write [...arr...curr],[]---> the initial value of the accumulator is [], but wouldn't it be okay to omit the initial value so that by default, the initial value is one the inner rays? Wouldn't that be fine?

Because at the end of the day you just want one array all values separated by commas.

1 Answer

Steven Parker
Steven Parker
210,867 Points

If you don't supply an initial value, the operation will start with the first element in the accumulator, so the accumulator would not be an array.

Will Albertsen
Will Albertsen
13,155 Points

So how come the code still works normally even if an empty array is not set as the initial value? Since the first value of the accumulator would be the string 'The Day the Earth Stood Still', would calling the spread operator on it not get you the following result?

["T", "h", "e", " ", "D", "a", "y", " ", "t", "h", "e", " ", "E", "a", "r", "t", "h", " ", "S", "t", "o", "o", "d", " ", "S", "t", "i", "l", "l"]
Steven Parker
Steven Parker
210,867 Points

Separating the strings into individual characters is not the objective of the exercise.