Is there a better way to turn a destructured array into an object in Javascript?
I'm using the axios API library, and when I perform multiple queries at once I get back an array with 4-5 API responses. I then want to wrap those into an object and pass to another function. Maybe there's a one-liner? Not that this is really a big deal, but I have a bunch of these throughout my application.
const [foo, bar, baz] = [1, 2, 3]
const obj = { foo, bar, baz }
console.log(obj)
=> {foo: 1, bar: 2, baz: 3}
_.zipObject(['foo', 'bar', 'baz'], [1, 2, 3])responseType(see Request Config). You could use json as theresponseType. Then in your js code, useJSON.parseso that the response is transformed into an object.console.log(( ([foo, bar, baz]) => ({ foo, bar, baz }) )([1, 2, 3]))