- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 06:03 AM
Hi,
I have a need in relation to arrays.
Ex.: I have an array that always consists of 5 elements, because I have limited my GlideRecord query to 5.
Array = [apple, lemon, orange, kiwi, banana]
I need to find the element in position 5 (banana) and store it in a variable.
I have found this thread, but it is the reverse activity - finding the position of the element.
Solved: How to find the position of an element in an array... - ServiceNow Community
Bring your magic!
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 08:07 AM
var Array = ['apple', 'lemon', 'orange', 'kiwi', 'banana'];
gs.info(Array[4]);
Results:
*** Script: banana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 04:03 PM
There are several ways to do this.
This way will work for any array of any length and will preserve the original array.