slice in javascript
var str1 = "Apple, Banana, Kiwi";
var res1 = str1.slice(7, 13);
var res2 = str1.slice(-12, -6);
var res3 = str1.slice(7);
var res4 = str1.slice(-12);
var res5 = str1.substring(7, 13); //substring() cannot accept negative indexes like slice.
var res6 = str1.substr(7, 9); // substr(start, length) is similar to slice(). second parameter of substr is length of string
document.write("<br>" + "slice:", res1);
document.write("<br>" + "slice -ve pos:", res2);
document.write("<br>" + "slice with only start pos:", res3);
document.write("<br>" + "slice with only -ve start pos", res4);
document.write("<br>" + "substring:", res5);
document.write("<br>" + "substr:", res6);