Substring in javascript

Something Like that:
substring

substring() is similar to slice().
The difference is that substring() cannot accept negative indexes.

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.substring(7, 13);
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”mMyZYd” default_tab=”result” user=”pradeepanvi”]See the Pen substring 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 *