javascript 简单复习

This commit is contained in:
estomm
2022-04-18 20:40:34 +08:00
parent c030d40264
commit bb9110d289
54 changed files with 4123 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
## 大小写转换
String 对象提供如下方法,用于大小写转换。
| 方法名 | 说明 |
| --- | --- |
| toUpperCase() | 把字符串转换为大写。|
| toLowerCase() | 把字符串转换为小写。|
```javascript
var msg = 'Hello World';
var lowerMsg = msg.toLowerCase();
var upperMsg = msg.toUpperCase();
console.log( msg );// Hello World
console.log( lowerMsg );// hello world
console.log( upperMsg );// HELLO WORLD
```
## 获取指定位置的字符
String 对象提供如下方法,用于获取指定位置的字符。
| 方法名 | 说明 |
| --- | --- |
| charAt() | 返回在指定位置的字符。|
| charCodeAt() | 返回在指定的位置的字符的 Unicode 编码。|
```javascript
var str = "HELLO WORLD";
console.log( str.charAt(2) );// L
console.log( str.charCodeAt(0) );// 72
```
## 检索字符串
String 对象提供如下方法,用于检索字符串。
| 方法名 | 说明 |
| --- | --- |
| indexOf() | 返回某个指定的字符串值在字符串中首次出现的位置。|
| lastIndexOf() | 从后向前搜索字符串。|
```javascript