Array destructuring vs indexed access

Benchmark created on


Setup

var array = ['ok'];
var empty = [];
var und = undefined;

Test runner

Ready to run.

Testing in
TestOps/sec
Array destructuring
const [result] = array || [];
const [no] = empty || [];
const [nono] = und || [];
ready
Index access
const result = array?.[0];
const no = empty?.[0];
const nono = empty?.[0];
ready

Revisions

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