Показать сообщение отдельно
  #2 (permalink)  
Старый 27.02.2010, 18:57
Кандидат Javascript-наук
Отправить личное сообщение для vk65535 Посмотреть профиль Найти все сообщения от vk65535
 
Регистрация: 21.11.2008
Сообщений: 114

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'));

Последний раз редактировалось vk65535, 27.02.2010 в 19:00.
Ответить с цитированием