Jin Yong
Jin Yong

Reputation: 43778

How can I cut the 1st char from a string in jquery?

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?

Upvotes: 4

Views: 2497

Answers (3)

user578895
user578895

Reputation:

Array.prototype.shift.apply(test);

Upvotes: 0

brendan
brendan

Reputation: 29986

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?

Upvotes: 3

Marek Karbarz
Marek Karbarz

Reputation: 29304

Why jQuery?? Just use plain old javascript:

var first = test.substring(0, 1)

Upvotes: 13

Related Questions