To get the first element of a string

Asked 2 years ago, Updated 2 years ago, 19 views

in javascript I'm using Internet Explorer 7.

Trying to get the first element of a string in JavaScript

var x = 'somestring';
alert(x[0]); // returns undefined

What's wrong with this code?

javascript

2022-09-22 21:59

1 Answers

Write the charAt function.

var x = 'some string';
alert(x.charAt(0)); // alerts 's'


2022-09-22 21:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.