I'm looking for the most concise way to convert an array to an object while plucking the field used as the key for each result.
This is the solution I found, and I'm wondering if there's an easier way.
r.table('product').fold({}, function(products, product) {
return products.merge(
r.object(
product('id').coerceTo('string'),
product.without('id')
)
);
})
Thanks!
Example
// Input:
[{ id: 0, price: 19.99 }, { id: 1, price: 24.99 }]
// Output:
{ "0": { price: 19.99 }, "1": { price: 24.99 } }