char-at.js
来自「这是《JavaScript学习源代码》一书的源代码」· JavaScript 代码 · 共 20 行
JS
20 行
// create and initialize two string variables
var str = "linger in", newstr = "";
// get the first and last letters of the str variable
var a = "First letter : " + str.charAt(0);
var z = "Final letter : " + str.charAt( str.length -1 );
// loop through each character and copy into newstr
// unless it's an i - then copy an o into newstr
for( var i = 0; i < str.length; i++ )
{
if( str.charAt(i) != "i" ) newstr += str.charAt(i);
else newstr += "o";
}
// display newstr and the first and last letters of str
var result = "STRINGS\n\n";
result += "New string : " + newstr + "\n";
alert( result + a + "\n" + z );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?