es5 if not array array vs es6 if not array array

Edit on GitHub

Setup

let input0 = ['foo', 'bar', 'baz'];
let input1 = 'foo';

Tests

  • es5 if not array array

    if (!Array.isArray(input0)) {
        input0 = [input0];
    }
    if (!Array.isArray(input1)) {
        input1 = [input1];
    }
  • es6 if not array array

    input0 = [...input0];
    input1 = [...input1];