Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value at a specific index of array In JavaScript?

Tags:

javascript

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?

like image 916
junaidp Avatar asked Nov 23 '11 07:11

junaidp


People also ask

How do you get a specific value from an array in JavaScript?

JavaScript Demo: Array.find() If you need to find the index of a value, use Array.prototype.indexOf() . (It's similar to findIndex() , but checks each element for equality with the value instead of using a testing function.) If you need to find if a value exists in an array, use Array.prototype.includes() .

How do you find the index value of a particular array?

To find the position of an element in an array, you use the indexOf() method. This method returns the index of the first occurrence the element that you want to find, or -1 if the element is not found. The following illustrates the syntax of the indexOf() method.

Can you pop a specific element from array in JavaScript?

You can remove elements from the end of an array using pop, from the beginning using shift, or from the middle using splice. The JavaScript Array filter method to create a new array with desired items, a more advanced way to remove unwanted elements.

What is array [- 1 in JavaScript?

As others said, In Javascript array[-1] is just a reference to a property of array (like length ) that is usually undefined (because it's not evaluated to any value).


1 Answers

Just use indexer

var valueAtIndex1 = myValues[1]; 
like image 74
Abdul Munim Avatar answered Oct 08 '22 20:10

Abdul Munim