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 trialCaleb Kleveter
Treehouse Moderator 37,862 PointsItems in arrays
How do I check to see how many items are in an array?
2 Answers
Joe Cochran
18,249 PointsAssuming an array called array:
array.length
or
array.size
array.count will only work on Will return the number of items in the array. For more info, check out the documentation on ruby arrays. Class: Array
Caleb Kleveter
Treehouse Moderator 37,862 PointsThanks for reminding me.
Joe Cochran
18,249 PointsGlad to help! I actually found out that there are three ways to do this. Array.length, Array.count, and Array.size. Here's a nice article that goes in to explaining what each method is, and why you would use it! Good for some morning reading: