Kita'arwa JavaScript String
- Hausa Previous Page Hausa JS Set
- Hausa Next Page Hausa JS Objects
JavaScript string
JavaScript 字符串存储一系列字符,例如 "Bill Gates"。
字符串可以是双引号或单引号内的任何文本:
let carName1 = "Volvo XC60"; let carName2 = 'Volvo XC60';
字符串索引(下标)是从零开始的:
第一个字符在位置 0,第二个在 1,依此类推。
如需有关字符串的知识,请访问我们的 JavaScript 字符串教程。
字符串属性和方法
通常,像 "Bill Gates" 这样的字符串不能有方法或属性,因为它们不是对象。
但是对于 JavaScript,方法和属性也可用于字符串,因为 JavaScript 在执行方法和属性时将字符串视为对象。
JavaScript 字符串方法和属性
Haukarau | Ƙarantaccen |
---|---|
at() | 返回字符串中指定索引的字符。 |
charAt() | 返回字符串中指定索引(位置)的字符。 |
charCodeAt() | 返回字符串中指定索引处字符的 Unicode 值。 |
codePointAt() | 返回字符串中指定索引(位置)的 Unicode 值。 |
concat() | 返回两个或多个连接的字符串。 |
constructor | 返回字符串的构造函数。 |
endsWith() | 返回字符串是否以指定值结尾。 |
fromCharCode() | 将 Unicode 值作为字符返回。 |
includes() | 返回字符串是否包含指定值。 |
indexOf() | 返回字符串中第一次出现指定值的索引(位置)。 |
lastIndexOf() | 返回字符串中最后一次出现指定值的索引(位置)。 |
length | 返回字符串的长度。 |
localeCompare() | 在当前区域设置下比较两个字符串。 |
match() | 在字符串中搜索值或正则表达式,并返回匹配项。 |
padEnd() | 在字符串末尾填充字符。 |
padStart() | 从字符串开头填充字符。 |
prototype | 允许您向对象添加属性和方法。 |
repeat() | 返回包含指定数量字符串副本的新字符串。 |
replace() | 在字符串中搜索模式,并返回替换第一个匹配项后的字符串。 |
replaceAll() | 在字符串中搜索模式,并返回替换所有匹配项后的新字符串。 |
search() | 在字符串中搜索值或正则表达式,并返回匹配项的索引(位置)。 |
slice() | 提取字符串的一部分并返回新字符串。 |
split() | 将字符串拆分为子字符串数组。 |
startsWith() | 检查字符串是否以指定字符开头。 |
substr() | 从字符串的指定索引(位置)开始提取指定数量的字符。 |
substring() | 提取字符串中两个指定索引(位置)之间的字符。 |
toLocaleLowerCase() | 使用主机的区域设置将字符串转换为小写字母并返回。 |
toLocaleUpperCase() | 使用主机的区域设置将字符串转换为大写字母并返回。 |
toLowerCase() | 返回转换为小写字母的字符串。 |
toString() | 将字符串或字符串对象作为字符串返回。 |
toUpperCase() | 返回转换为大写字母的字符串。 |
trim() | 返回去除空格的字符串。 |
trimEnd() | 返回去除末尾空格的字符串。 |
trimStart() | 返回去除开头空格的字符串。 |
valueOf() | 返回字符串或字符串对象的原始值。 |
提示:所有字符串方法都返回新值。它们不会改变原始变量。
字符串 HTML Wrapper 方法
HTML 包装器方法返回包装在 HTML 标记内的字符串。
这些不是标准的方法,可能无法按预期工作。
Haukarau | Ƙarantaccen |
---|---|
anchor() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
big() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
blink() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
bold() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
fixed() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
fontcolor() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
fontsize() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
italics() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
link() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
small() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
strike() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
sub() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
sup() | Fannar ɗanɗin taɗa ɗanɗin ɗanɗin ɗanɗin |
String ɗanɗin
Hausa Strings are a basic data type of JavaScript. The String class provides methods for operating on primitive string values.
Hausa String object's Hausa length attributeHausa Declared the number of characters in the string.
Hausa The String class defines a large number of methods for operating on strings, such as extracting characters or substrings from strings, or retrieving characters or substrings.
Hausa Note:Hausa JavaScript strings are immutable (immutable), and the methods defined in the String class cannot change the content of the string. Like Hausa String.toUpperCase() Hausa Such methods return a completely new string, not modifying the original string.
Hausa In earlier Netscape code base JavaScript implementations (such as Firefox implementations), the behavior of strings is like a read-only character array. For example, to extract the third character from a string s, you can use s[2] instead of the more standard s.charAt(2). Additionally, when applying a for/in loop to a string, it will enumerate the array index of each character in the string (but note that the ECMAScript standard stipulates that the length property cannot be enumerated). Because the array behavior of strings is not standard, it should be avoided.
Hausa Supplementary Books
Hausa For more information, please read the relevant content in the JavaScript Advanced Tutorial:
- Hausa ECMAScript Reference Type
- Hausa Reference types are usually called classes (class) or objects. This section explains the predefined reference types of ECMAScript.
- Hausa Previous Page Hausa JS Set
- Hausa Next Page Hausa JS Objects