Does anyone know how can I cut the 1st char from the string in jquery?
Example: If I have string as following:
var test = '3265';
How can I cut only the 1st char so that the output will be '3' instead?
mu is too short
436k71 gold badges863 silver badges822 bronze badges
asked May 10, 2011 at 2:14
Jin Yong
44k72 gold badges145 silver badges195 bronze badges
3 Answers 3
Why jQuery?? Just use plain old javascript:
var first = test.substring(0, 1)
answered May 10, 2011 at 2:16
Marek Karbarz
29.4k6 gold badges55 silver badges73 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
No need for jQuery, straight javascript:
var test = '3265'
var first = test.slice(0,1);
Some thoughts on the differences between .substring(), .substr() and .slice() : http://rapd.wordpress.com/2007/07/12/javascript-substr-vs-substring/
also: What is the difference between String.slice and String.substring?
answered May 10, 2011 at 2:16
brendan
30.1k20 gold badges70 silver badges109 bronze badges
Comments
Array.prototype.shift.apply(test);
answered May 10, 2011 at 4:00
user578895
Comments
lang-js