4

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
  • 426,620
  • 70
  • 833
  • 800
Jin Yong
  • 42,698
  • 72
  • 141
  • 187

3 Answers3

13

Why jQuery?? Just use plain old javascript:

var first = test.substring(0, 1)
Marek Karbarz
  • 28,956
  • 6
  • 53
  • 73
3

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?

Community
  • 1
  • 1
brendan
  • 29,308
  • 20
  • 68
  • 109
0
Array.prototype.shift.apply(test);
animuson
  • 53,861
  • 28
  • 137
  • 147