Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS how to do "substr"? [duplicate]

Possible Duplicate:
javascript substring

How can I do substr (php) in JS?

Example code from PHP:

<?php
$rest = substr("abcdef", -1);    // returns "f"
$rest = substr("abcdef", -2);    // returns "ef"
$rest = substr("abcdef", -3, 1); // returns "d"
?>
like image 600
Dudu Avatar asked Jan 18 '23 10:01

Dudu


2 Answers

It is very similar to PHP:

var rest = "abcdef".substr(start, length);

You also can read more about this function here: http://www.w3schools.com/jsref/jsref_substr.asp

like image 129
user1123379 Avatar answered Jan 25 '23 14:01

user1123379


The following will reproduce it.

"abcdef".substr(-1);
"abcdef".substr(-2);
"abcdef".substr(-3, 1);
like image 44
Martin. Avatar answered Jan 25 '23 15:01

Martin.