千鋒教育JavaScript全套視頻教程(10天學(xué)會(huì)Js,前端javascrip

?字符串
1.定義
var str=woshilcy
2.訪問(wèn)
使用索引位置來(lái)訪問(wèn)字符串中的每個(gè)字符
var character= str[0] //w
轉(zhuǎn)義字符
在 JavaScript 中,字符串寫(xiě)在單引號(hào)或雙引號(hào)中。
因?yàn)檫@樣,以下實(shí)例 JavaScript 無(wú)法解析:
?"We are the so-called "Vikings" from the north."
字符串 "We are the so-called " 被截?cái)唷?/p>
如何解決以上的問(wèn)題呢?可以使用反斜杠 (\) 來(lái)轉(zhuǎn)義 "Vikings" 字符串中的雙引號(hào),如下:
?"We are the so-called \"Vikings\" from the north."
?反斜杠是一個(gè)轉(zhuǎn)義字符。 轉(zhuǎn)義字符將特殊字符轉(zhuǎn)換為字符串字符:
字符串可以是對(duì)象
可以使用字符串創(chuàng)建
?var firstName = "John"
我們也可以使用 new 關(guān)鍵字將字符串定義為一個(gè)對(duì)象??//new 一個(gè)對(duì)象
var firstName = new String("John")??
var x = "John";
var y = new String("John");
typeof x // 返回 String
typeof y // 返回 Object
字符串屬性和方法
字符串屬性?legth
字符串方法
charCodeAt() 返回在指定的位置的字符的 Unicode 編碼。
indexOf() 返回某個(gè)指定的字符串值在字符串中首次出現(xiàn)的位置。 slice() ?復(fù)制????????提取字符串的片斷,并在新的字符串中返回被提取的部分。
split() 把字符串分割為字符串?dāng)?shù)組。??? xx 字符串 轉(zhuǎn) 數(shù)組 toLowerCase() 把字符串轉(zhuǎn)換為小寫(xiě)。 toUpperCase() 把字符串轉(zhuǎn)換為大寫(xiě)。 toString() 返回一個(gè)字符串。
標(biāo)簽: