Take an array and make an object out of flipped indices/values

Viewed 73

Is there a more straightforward way in lodash to achieve the following,

var o = _.reduce([2, 3, 7], function(acc, v, i) {
    acc[v] = i || "0";
    return acc;
}, {});

Result,

Object {2: "0", 3: 1, 7: 2}
3 Answers
Related