⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 char-at.js

📁 这是《JavaScript学习源代码》一书的源代码
💻 JS
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -