Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

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

Not applicable

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.