O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finding What Character Is at a Specific Location in a String

var s = "In The Darkness Bind Them"; s.charAt(7); //returns 'D' s[7]; // also returns 'D'

String objects provide the charAt(offset), which returns the character contained at the offset specified. Also, strings in JavaScript are basically arrays of characters, so you can get the character at a specific offset using stringName[offset]. Keep in mind that the offsets are always zero based, so their first character is at offset 0.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required