- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 10:42 AM
I have created an array that has the variable questions input as values in the array including the spaces in the variable name. I am having trouble getting the indexOf function to return TRUE even though when I log the values being compared and they look the same.
Example-
Array [Variable question one, Variable question two, Variable questions three]
When I do an index of this array for "Variable question one" I am not getting a true value back.
Do I need to encode or otherwise remove the spaces or is that not an issue to worry about, and the problem is elsewhere?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 10:51 AM
Hello,
The spaces shouldn't be an issue since they are considered as strings usually. IndexOf, if given with spaces will work.
Sometimes the issue might be due to leading/trailing spaces (kind of prefix or suffix like “ jlaps” instead of “jlaps”.
In your example - if questions = ["Variable question one", "Variable question two", "Variable question three"];
gs.print(questions.indexOf("Variable question one")); > Should return 0
Note: Use logs to identify which data type are these fields for further analysis.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 10:51 AM
Hello,
The spaces shouldn't be an issue since they are considered as strings usually. IndexOf, if given with spaces will work.
Sometimes the issue might be due to leading/trailing spaces (kind of prefix or suffix like “ jlaps” instead of “jlaps”.
In your example - if questions = ["Variable question one", "Variable question two", "Variable question three"];
gs.print(questions.indexOf("Variable question one")); > Should return 0
Note: Use logs to identify which data type are these fields for further analysis.