The fromPairs
method from lodash allows you to create an object from an array of key-value pairs. Here is an example of how to use it:
index.tsx168 chars8 lines
In this example, we first require lodash and define an array of key-value pairs. We then pass this array to the fromPairs
method and assign the resulting object to the obj
variable. The output of the program when we log obj
to the console will be:
index.tsx19 chars2 lines
This is a simple example, but fromPairs
can be very useful when working with dynamic data structures that need to be transformed into objects in a functional and concise way.
gistlibby LogSnag