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
436k71 gold badges863 silver badges822 bronze badges
asked May 10, 2011 at 2:14

3 Answers 3

13

Why jQuery?? Just use plain old javascript:

var first = test.substring(0, 1)
answered May 10, 2011 at 2:16
Sign up to request clarification or add additional context in comments.

Comments

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?

answered May 10, 2011 at 2:16

Comments

0
Array.prototype.shift.apply(test);
animuson
54.9k28 gold badges142 silver badges150 bronze badges
answered May 10, 2011 at 4:00

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.