JSFiddle - React, Tailwind, and code Playground
by Harish Singh
HTML
<div>
strpos('Hello Howdy', 'w', 5) <br/> <span id="strpos"></span>
</div>
<br/><br/>
<div>
"Hello, how are you?" split and join <br/> <span id="splitjoin"></span>
</div>
<br/><br/>
<div>
"Hello world!" get world! with substr <br/> <span id="substr"></span>
</div>
<br/><br/>
<div>
" Hello world! " trim <br/> <span id="trimstr"></span>
</div>
JavaScript
function strpos (haystack, needle, offset) {
var i = (haystack+'').indexOf(needle, (offset || 0));
return i === -1 ? false : i;
}
document.getElementById('strpos').innerHTML=""+strpos('Hello Howdy', 'w', 5);
var strArr = "Hello, how are you?".split(',');
strArr = strArr.join('<br>');
document.getElementById('splitjoin').innerHTML=strArr;
var str = "Hello world!";
var res = str.substr(5,str.length);
document.getElementById('substr').innerHTML=res;
var str = " Hello world! ";
document.getElementById('trimstr').innerHTML=str.trim();