- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript String slice
JavaScript Strings
JavaScript String slice
slicetakes a piece out of a string without changing the original.
It works just like slice on an array.
The end index is not included, which catches people out.
Example
Example
javascript
const text = "JavaScript";
console.log(text.slice(0, 4));
console.log(text.slice(4));The output is Java then Script.
