For a basic example of the lodash at method I put together a quick example that has to do with a color object. In this color object I have property key value pairs for each color channel, and and alpha value. I want an array where the first index value is the red channel, followed by green, blue, and finally the alpha channel value. The lodash _.at method can be used to create that array, and in the oder that I want the index values.
I just call the lodash _.at method, pass the color object as the first argument, and then an array of paths to each property that I want in the new array. The order in which the paths are given will be the order in which the values will be indexed in the array that will be returned by _.at.
I have an array of my color objects then I can again use the lodash _.at method to create and array of arrays by using a method like lodash map for example. I can also create just one object by changing the value of the paths string to do so.
In this section I will be going over a few quick examples that do the same things that I have outline with the lodash examples, only this time around I am just working with javaScrit by itself.
One way to do the same thing would be to just create a new array with the bract syntax, and then use the dot syntax to access each property in the source object. When doing so I can access each property in the source object in the desired order.
The same trick can be done when it comes to nested objects also.
So then the lodash at method is a way to go about creating an array of values from a source object and an array of paths to the various values in the source object. If you enjoyed this post you might want to check out my main post on lodash, my post on lodash array methods in general, or one of my many other posts on lodash.