Test name | Executions per second |
---|---|
flatten | 9219310.0 Ops/sec |
reduce | 1425170.0 Ops/sec |
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
window.obj = {};
for (var i = 0, len = 10; i < len; i++) {
var arr = []
obj['key' + i] = arr
for (var n = 0, len = 10; n < len; n++) {
arr.push({ ['key' + n]: n });
}
}
_.flatten(obj, (acc, val, key) => {
acc[key] = val.map(d => ({ label: key, value: val }));
return acc;
}, {})
Object.entries(obj).reduce((acc, [key, val]) => {
acc[key] = val.map(d => ({ label: key, value: val }));
return acc;
}, {})