Character access
There are two ways to access an individual character in a string. The first is the charAt method:
return 'cat'.charAt(1); // returns "a"
The other way is to treat the string as an array, where each index corresponds to an individual character:
return 'cat'[1]; // returns "a"
The second way (treating the string as an array) is not part of ECMAScript; it's a JavaScript feature (and not supported in all browsers).
In both cases,
attempting to set an individual character won't work. Trying to set a character through charAt results in an error, while trying to set a character via indexing does not throw an error, but the string itself is unchanged.
Остаются только substr и replace.
alert('Hello world!'.replace(/^(.{6})./, '$1W'));