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 trialOsiris Maldonado
699 PointsCan an array of items be added with the .append function?
I know that an array of new items can be appended using the +=
todo += ["Additional Stuff", "More Stuff"]
But can an array be added using .append? or can .append achieve just single elements?
Thanks in advance!
2 Answers
Steve Hunter
57,712 PointsThe .append
call is expecting a single element. If you have an array of strings and try to .append
another array of strings you'll get, '[String]' is not convertible to String
Steve Hunter
57,712 PointsI guess so, yes. Or you could use a for loop to iterate through the second array and append each element one by one, perhaps?
Osiris Maldonado
699 PointsOsiris Maldonado
699 PointsOk, I see, so .append is only useful for adding single elements. I assume that to add multiple elements, the best bet is to use '+=' ?