if string contains else if it doesn't contain - Javascript -


i trying check whether string, in case document title, contains word, , if display "str1" if doesn't contain word display "str2"

var str1 = document.title.replace(/new - business name/i, ''); var str2 = document.title.replace(/ - business name/i, ''); if(document.title.indexof("sale") == 1){ document.write(str1);}  else if(document.title.indexof("sale") != 1){ document.write(str2);} 

check indexof docs

var str1 = document.title.replace(/new - business name/i, ''); var str2 = document.title.replace(/ - business name/i, ''); if(document.title.indexof("sale") > -1){ document.write(str1); } else if(document.title.indexof("sale") === -1){ document.write(str2); } 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -