- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 06:41 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 06:43 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 06:43 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 06:44 AM
Try by
gs.info(array.indexOf("5"));
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 06:44 AM
you can try indexOf and also it needs in following format.
var array = ['1','2','3','4','5','6','7','8','9','10','11'];
gs.info(array.indexOf("5"));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 06:46 AM
Try following.
var array = [1,2,3,4,5,6,7,8,9,10,11];
gs.info(array.indexOf(5));
as the element in your array are not strings so the passing value cannot be string to.