Change default key from JS object

202 Views Asked by At

How can I change the default keys generated by the transform() method from Lodash for this object. They must start from 1, instead of 0.

function getHashValues(section, matchExp) {
    var picked = _.transform(section, function(result, value, key) {
        var matches = key.match(new RegExp(matchExp));
        if (matches) {
            result[matches[2]] = result[matches[2]] || {};
            result[matches[2]][matches[1]] = value;
        }
    }, {});

    // Log
    console.log(typeof picked); // object
    console.log(picked); // Object {0: Object, 1: Object, 2: Object, 3: Object, 4: Object, 5: Object, 6: Object, 7: Object, 8: Object, 9: Object}

    return picked;
}
0

There are 0 best solutions below