Javascript search and indexOf similarity without Regex
by Kabeer Shah
HTML
<p id="demo">Without a <a href='http://www.w3schools.com/js/js_regexp.asp'>regex</a>, there is <a href='http://stackoverflow.com/a/34282912/2404470'>no practical difference</a> between <a href='http://www.w3schools.com/jsref/jsref_indexof.asp'>indexOf</a> and <a href='http://www.w3schools.com/jsref/jsref_search.asp'>search</a></p>
<button onclick="FromSearch()">From search</button>
<button onclick="FromindexOf()">From indexOf</button>
<p id="Location"></p>
JavaScript
function FromSearch() {
var str = document.getElementById("demo").innerText;
var n = str.search("difference");
document.getElementById("Location").innerHTML = n;
}
function FromindexOf() {
var str = document.getElementById("demo").innerText;
var n = str.indexOf("difference");
document.getElementById("Location").innerHTML = n;
}