HTML Preparation code:
AخA
 
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
Script Preparation code:
x
 
function format_lodash(data) {
    return data.map(({ id, label, ...properties}) => {
        return { id, label, properties: _.mapValues(properties, v => v[0]) };
    });
}
function format_pure(data) {
    return data.map(({ id, label, ...properties}) => {
        for (let [key, value] of Object.entries(properties)) { properties[key] = value[0] }
        return { id, label, properties};
    });
}
Tests:
  • Lodash Test

     
    const input = [{
            id: 1,
            label: 'label 1',
            property_1: ['prop_1'],
            property_2: ['prop_2']
        },
        {
            id: 2,
            label: 'label 2',
            property_3: ['prop_3'],
            property_4: ['prop_4']
        }
    ]
    console.log(format_lodash(input))
  • Pure JS Test

     
    const input = [{
            id: 1,
            label: 'label 1',
            property_1: ['prop_1'],
            property_2: ['prop_2']
        },
        {
            id: 2,
            label: 'label 2',
            property_3: ['prop_3'],
            property_4: ['prop_4']
        }
    ]
    console.log(format_lodash(input))
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Lodash Test
    Pure JS Test

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 7 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Chrome 135 on Windows
View result in a separate tab
Test name Executions per second
Lodash Test 72058.3 Ops/sec
Pure JS Test 70588.2 Ops/sec