Substr in javascript

Something Like that:
substr

substr() is similar to slice().
The difference is that the second parameter specifies the length of the extracted part.

For example I want to written Banana.

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var str = "Apple, Banana, Kiwi";
var res = str.substr(7, 6);
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”ZJGjBO” default_tab=”js,result” user=”pradeepanvi”]See the Pen Substr in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see Banana

Leave a Reply

Your email address will not be published. Required fields are marked *