user3578984
user3578984

Reputation:

Is there function like parseInt() or parseFloat() but with a letter?

I want function like parseInt() or parseFloat(), but it will output letter. In better option it will output only first letter. Like this:

var text = Hello World!
var newval = parseLetter(text);
Output: H

Upvotes: 1

Views: 156

Answers (2)

Ali Mehdi
Ali Mehdi

Reputation: 924

Use this:

function parseLetter(letter){
    return letter.charAt(0);
}

It will return the first letter of your string

Upvotes: 0

Guna
Guna

Reputation: 316

You want to get the first letter of your string as your output. Isn't it? If That is the case, try the following..,

var text = "Hello World!"
var newval = text.charAt(0);

Upvotes: 2

Related Questions