Splicing Strings

var s1 = "The play's the thing"; var s2 = s1.splice(4,8); // s2 = "play"

You can carve a string into substrings using .splice(start, end) by specifying the starting index and the ending index. The section of the string starting with the character at the index specified by start and ending with the character just before end index is returned. All indexes are zero based.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.