Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Well, there we have it—everything you’ve always wanted to know about collections and iterating in CoffeeScript.
We first looked at arrays and what makes them tick in CoffeeScript. We looked at a few fun tricks CoffeeScript makes possible when dealing with arrays: testing to see if a value is in an array, swapping assignment of variables, and, finally, capturing the elements of an array easily into variables.
Next we looked at ranges. We saw how to construct arrays of numbers using the range syntax. We also looked at how ranges can be used to manipulate existing arrays by grabbing sections of the array and even replacing sections of an array with other values.
After ranges, we moved on to objects in CoffeeScript. We looked at the different rules around constructing objects. We looked at how to set and get attributes on the objects we create. Using a modified object syntax, we saw how we could pull out deeply nested attributes in an object and assign them to variables.