Inbound Action - indexOf for Array Position

Steven Parker
Giga Sage

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
5 REPLIES 5