Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

slice string javascript

let str = "Learning to code";

// slice from index 2 to end
let str1 = str.slice(2);
console.log(str1);

// slice from index 1 to index 8
let str2 = str.slice(1, 8);
console.log(str2);

// slice from index 5 to index (str.length - 3)
let str3 = str.slice(5, -3);
console.log(str3);

// slice from index 100 to end (returns '')
let str4 = str.slice(100);
console.log(str4);

// slice from index 0 to end of string
let str5 = str.slice(0);
console.log(str5);
Source by www.tutorialstonight.com #
 
PREVIOUS NEXT
Tagged: #slice #string #javascript
ADD COMMENT
Topic
Name
5+9 =