Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoshua szkodlarski
8,604 PointsFinish the code by adding the array method that combines all of the items in an array into a single string. var studen
Finish the code by adding the array method that combines all of the items in an array into a single string. var students = ["Sally", "Joan", "Raphael", "Sam"]; var message = "Hello " + students. (", "); Submit Answer
what do i do?
2 Answers
Jonathan Fernandes
Courses Plus Student 22,784 PointsRemember, methods are called on the array to provide some functionality. Treehouse provides a couple useful ones. Specifically, you are looking at the join method. Here is an example array:
var myArrayOfDays = [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
];
If I wanted to combine the elements in my array into a string, I would call the join method on it. The join method takes one argument, what you want to separate each element in your array. So here would be the results of me running the join method:
myArrayOfDays.join(", ");
// would return:
// "Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday"
// And if I pass just a space as a string:
myArrayOfDays.join(" ");
// It would return:
// "Monday Tuesday Wednesday Thursday Friday Saturday Sunday"
// And if I pass just an empty string:
myArrayOfDays.join("");
// It would return:
// "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"
I hope that helps and makes sense. Let me know if you would like me to explain a bit more and happy learning! :)
ceriannejackson
23,759 PointsHave you watched the 'Useful Array Methods' video? The correct method is used in there :)