Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  61] [ 7]  / answers: 1 / hits: 59979  / 13 Years ago, fri, june 10, 2011, 12:00:00
id = '01d0';
document.write('<br/>'+id.substr(0,-2));

How can I take a string like '01d0and get the01` (all except the last two chars)?


In PHP I would use substr(0,-2) but this doesn't seem to work in JavaScript.


How can I make this work?


More From » string

 Answers
22

You are looking for slice() (also see MDC)



id.slice(0, -2)

[#91772] Wednesday, June 8, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stacied

Total Points: 124
Total Questions: 84
Total Answers: 98

Location: Ivory Coast
Member since Sun, Mar 7, 2021
3 Years ago
;