How do you get the first element from a JavaScript array?

Building on what you both said, I’d say that using bracket notation with [0] is definitely the fastest and cleanest way to javascript get first element of array. It’s easy to remember and super performant:

var first = ary[0];

Also, if you want to be extra safe in some cases (like when the array might be empty), you could add a quick check:

var first = ary.length > 0 ? ary[0] : undefined;

But most of the time, ary[0] is all you need. It’s a neat, no-nonsense approach I use every day.