String slice()
slice(startingPosition [, whereToStop(exclusive)])
returns a substring and accepts either one or two arguments.
If the second argument is omitted, it is default to the ending position.
slice() does not alter the value of the string itself.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script type="text/javascript">
var stringValue = "hello world";
document.writeln(stringValue.slice(3)); //"lo world"
</script>
</head>
<body>
</body>
</html>
A negative argument tells to do the sub string from the end.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script type="text/javascript">
var stringValue = "hello world";
document.writeln(stringValue.slice(-3)); //"rld"
document.writeln(stringValue.slice(3, -4)); //"lo w"
</script>
</head>
<body>
</body>
</html>
Home
JavaScript Book
Essential Types
JavaScript Book
Essential Types
String:
- The String Type
- String length property
- String charAt()
- String charCodeAt()
- String concat()
- String slice()
- String substr()
- String substring()
- String indexOf()
- String lastIndexOf()
- String trim() Method
- String toLowerCase()
- String toLocaleLowerCase()
- String toUpperCase()
- String toLocaleUpperCase()
- String match()
- String search()
- String replace()
- String split()
- String localeCompare() Method
- String fromCharCode() Method
- String HTML Methods