find a faster way to return first element of array

Benchmark created on


Teardown

const sku = {
	commercialMessages: ["value"]
}

Test runner

Ready to run.

Testing in
TestOps/sec
baseline
const obj = {}
    if (sku.commercialMessages?.[0]) {
        obj.commercialMessages = sku.commercialMessages.slice(0, 1);
    }
ready
improvement
const obj = {}
    if (sku.commercialMessages?.[0]) {
        obj.commercialMessages = sku.commercialMessages.slice(0, 1);
    }
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.