I have an array and simply want to get the element at index 1.
var myValues = new Array();
var valueAtIndex1 = myValues.getValue(1); // (something like this)
How can I get the value at the 1st index of my array in JavaScript?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can access an element at a specific index using the bracket notation accessor.
On newer browsers/JavaScript engines (see browser compatibility here), you can also use the
.at()method on arrays.On positive indexes, both methods work the same (the first one being more common).
Array.prototype.at()however allows you to access elements starting from the end of the array by passing a negative number. Passing-1will give the last element of the array, passing-2the second last, etc.See more details at the MDN documentation.