I used to keep a cheat sheet of all the methods I could find for all my tasks, but then I realized that I only needed to look at things like forEach and push to know what I needed to know. This cheat sheet is an attempt to make up for that. Its also an attempt to get me to actually look at the code. At the very least it will give me a better understanding of how arrays operate.
I have to admit that the first time I saw this code I was floored. I thought to myself, “Aha!” And I’m glad I did. Its a pretty amazing thing that I’ve found.
The trick is to create the array by calling a method on an object and then creating a new array out of that object. Using the push method as an example, we can do this by calling the push method on the object, then pushing the result into the new array.
You can do a lot of things with arrays. For example, we can use them to hold multiple objects in one place. We can also do things like loop over them in order to perform operations on them. The great thing about arrays is that they are easy to use. Lets create a new array with the object, loop over it, then create a new array with the property that we want to loop over.