How to get the first element of an array?

MacMac picture MacMac · Nov 3, 2010 · Viewed 886.3k times · Source

How do you get the first element from an array like this:

var ary = ['first', 'second', 'third', 'fourth', 'fifth'];

I tried this:

alert($(ary).first());

But it would return [object Object]. So I need to get the first element from the array which should be the element 'first'.

Answer

John Hartsock picture John Hartsock · Nov 3, 2010

like this

alert(ary[0])