Inbound Action - indexOf for Array Position
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 06:26 AM
So I have created an inbound action and I am storing the email body text in a variable, splitting it on line breaks, and looking for the array position of specific text.
var str = email.body_text;
var arr = str.split('\n');
This code below returns 569, which makes sense because it's where the text is found if the body of the email was one long string, but isn't what I need:
var additionalData = arr.toString().indexOf('Additional data:');
This code below returns the value "Additional data:" which is what I am currently looking for in the arr variable from above:
var additionalData = arr[50];
This code below returns -1, which means it didn't find the text "Additional data:".
var additionalData = arr.indexOf('Additional data:');
Why does that last code not return 50, which is the position of "Additional data:" in the array? The 2nd example I show targets position 50 in the array and returns the exact value I am trying to use in the indexOf in the final example.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 01:41 PM
That's what I suspected.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/