In lodash there is the from pairs array method that can create a new object where each key is the value of the first element of a nested array in an array of arrays, and the value is the second element of an array nested in an array. It is the inversion of the lodash to pairs method that does the opposite of this by creating such an array of arrays from an object.
So lets say you have an array, and each element in that array is another array. In addition each nested array has a first element that you want to be a key value, and a second element that you want to be a value of that key value in a new object. The lodash from pairs method can be used to do just that.
just call the lodash from pairs method and pass the array of arrays to it. The result that is returned will be the object that you want where each key name is the first element of a nested array, and each value is then then second.
The lodash _.toPairs method is the inverse of the lodash .FromPairs method. If I pass an object to it, I am given an array of arrays where the keys and values are the first and second elements of each nested array for each key value pair in the given object.
While loops are great but there are also of course a number of useful array prototype methods that can also prove to be useful for these kinds of tasks. In this example I am using the array map method to create an array of keys, and a array of values, and then I am using the array for each method to set the values for a new object with these arrays.
In some cases I might want to cerate an array of key names, and values first like this, however for the most part this kind of solution might still prove to be a little more complex that it needs to be actually.
So then yet another option would be to just use the array for each method to create an object from an array of arrays of key value pairs.
There are still some methods that do take at least a little time to write though as there may not be a native counterpart method at all. Also there may be a native method, but it still may be relatively new, so often I might have to make use of a ploy fill method to make sure it is there. It is also possible to create customs builds of lodash which is often the root that a developer might utility want to go with a general utilities library. However getting into that may be a matter for a whole other post.