indexOf doesn't match the exact string?

gokulraj
Giga Expert

Hi team,

I have a requirement to get the exact string comparison results.

if my condition is like [ if (emailTo.indexOf("networkoperation@test.com") != -1) ]

it will also satisfy the conditions if the email To contains like the following("operation@test.com")  

How to find the exact string matching?

18 REPLIES 18

Harsh Vardhan
Giga Patron

use startsWith()

if (emailTo.startsWith("networkoperation@test.com")) 

 

if the email TO contains "networkoperationteam@test.com"  means the startsWith condition will match right?

Correct me if I was wrong

i have updated the script

 

var emails='networkoperation@test.com';
if (emails.startsWith("operation@test.com"))
{

gs.print('hello');
}
else
{
gs.print('not hello');
}

 

if in variables i have define "networkoperation@test.com" and i tried to match with "operation@test.com" then it will go to the else condition.

I will test this and let you know.