Searching for Strings with indexOf in Javascript -
i'm still having problems understanding indexof functionality correctly, or there else can't see.
i'm using loop search text strings/segments in url:
for(var = 0; < links.length; i++) { element = links[i]; if(element.href.indexof(segment) !== -1) { return true; }
if url example: http://www.anywebsite.com/this_is_my_text?some¶meters
, segment = "this_is_my_text"
it works fine.
however, if url looks this: http://www.anywebsite.com/this_is_my_text
and segment = "this_is_my_text"
the segment/string not found , function (around loop) returns false , not true.
what doing wrong? can't see it.
thanks lot in advance!
i tested here: http://jsfiddle.net/en50c13z/ :
var u1 = 'http://www.anywebsite.com/this_is_my_text?some¶meters , segment = "this_is_my_text"'; var u2 = 'http://www.anywebsite.com/this_is_my_textand segment = "this_is_my_text"'; if(u2.indexof('segment') !== -1) { return alert('found'); }
i added '' in if statement around 'segment' , working in both cases now, before edit both not working
Comments
Post a Comment