How to find the position of an element in an array?

Not applicable

How to find the position of an element in an array?

Example:

var array = [1,2,3,4,5,6,7,8,9,10,11];

I have to find the position of element '5' in above array.

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

hello ,

you can try this 

var array= [1,2,3,4,5,6,7,8,9,10,11];

var position = array.indexOf(5);

Hope this helps 

Mark the answer correct if this helps you

 

View solution in original post

5 REPLIES 5

Lasse Korsgaar1
Tera Contributor

I hope you can help me out here. I have the reverse need. I need to find the element in a certain position.

 

Ex.

var array = [apple, lemon, banana]

How do I find and store the value in position 3 (banana)?

 

Thanks.