Check if Array

Because arrays are objects, typeof names gives "object". To check if something is an Array, use Array.isArray:

const names = ['Jack', 'Laura', 'Paul', 'Megan'];

typeof names;
// => "object"

Array.isArray(names);
// => true

const object = {};
Array.isArray(object);
// => false

You might be tempted to use names instanceof Array, and that can work, but not under all circumstances. Read this article for more information.