Js String对象api函数解析

String.anchor()函数

 let teststr="abcdefg";
 console.log(teststr.anchor("Aname"))//<a name="Aname">abcdefg</a>

Returns an a HTML anchor element and sets the name attribute to the text value
函数解释的是将字符串的内容包装成a便签的elemnet并且可以传入一个字符串设置a标签的name。

String.big()函数

 let teststr="abcdefg";
 console.log(teststr.big()) //<big>abcdefg</big>

(method) String.big(): string
Returns a big HTML element
此函数没有参数,直接讲string标签返回成big element

String.blink()函数

 let teststr="abcdefg";
 console.log(teststr.blink())//<blink>abcdefg</blink>     

(method) String.blink(): string
Returns a blink HTML element
此函数没有参数,直接讲string标签返回成blink element

String.blod()函数

 let teststr="abcdefg";
 console.log(teststr.blod())//<b>abcdefg</b>    

(method) String.bold(): string
Returns a b HTML element
此函数没有参数,直接讲string标签返回成b element

String.charAt()函数

 let teststr="abcdefg";
 console.log(teststr.charAt(2))//c  

(method) String.charAt(pos: number): string
Returns the character at the specified index.
@param pos — The zero-based index of the desired character.

此函数传入一个number类型的变量,并且截取对应下标的字符并返回。

String.charCodeAt()函数

 let teststr="abcdefg";
 console.log(teststr.charCodeAt(2))//99

(method) String.charCodeAt(index: number): number
Returns the Unicode value of the character at the specified location.
@param index — The zero-based index of the desired character. If there is no character at the specified index, NaN is returned.

此函数传入一个number类型的变量,并且截取对应下标的字符的并返回。charCodeAt() 方法可返回指定位置的字符的 Unicode 编码。这个返回值是 0 - 65535 之间的整数。方法 charCodeAt() 与 charAt() 方法执行的操作相似,只不过前者返回的是位于指定位置的字符的编码,而后者返回的是字符子串。

String.codePointAt()函数

 let teststr="abcdefg";
 console.log(teststr.codePointAt(2))//99 

(method) String.codePointAt(pos: number): number
Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point value of the UTF-16 encoded code point starting at the string element at position pos in the String resulting from converting this object to a String. If there is no element at that position, the result is undefined. If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos.

此函数传入一个number类型的变量,并且截取对应下标的字符的并返回。charPointAt() 方法可返回指定位置的字符的 Unicode 编码。方法与 charCodeAt() 方法执行的操作相似,charCodeAt方法对于使用四个字节存储的字符无法返回正确的码点值,功能存在一定缺陷。codePointAt弥补此缺陷,不但可以返回两个字节存储的字符的码点值,也可以返回四个字节存储字符的码点值。

String.concat()函数

 let teststr="abcdefg";
 console.log(teststr.concat("--concatvalue"))//abcdefg--concatvalue
 console.log(teststr)                    //abcdefg

(method) String.concat(…strings: string[]): string
Returns a string that contains the concatenation of two or more strings.
@param strings — The strings to append to the end of the string.

此函数接受一个string数组,或者多个string对象,将传进来的string拼接在当前对象的后面,并且返回一个新的string数组,不影响原始的string。

String.endsWith()函数

 let teststr="abcdefg";
 console.log(teststr.endsWith("abc",3))//true
  console.log(teststr.endsWith("abc",4))// false

(method) String.endsWith(searchString: string, endPosition?: number): boolean
Returns true if the sequence of elements of searchString converted to a String is the same as the corresponding elements of this object (converted to a String) starting at endPosition – length(this). Otherwise returns false.

此函数第一个参数为一个string对象,第二个是一个number类型的数据,在当前string中的nmber下标向前匹配,若从第一个字符串开始能与传入得string匹配则返回true,否则返回false。

String.fixed()函数

 let teststr="abcdefg";
 console.log(teststr.fixed()) //<big>abcdefg</big>

(method) String.fixed(): string
Returns a tt HTML element
此函数没有参数,直接讲string标签返回成tt element

String.fontcolor()函数

 let teststr="abcdefg";
 console.log(teststr.fontcolor("blue")) //<font color="blue">abcdefg</font>

(method) String.fontcolor(color: string): string
Returns a HTML element and sets the color attribute value

次函数接收一个string并且返回一个font html elment将传入 的string设置为font标签的color属性

String.fontsize()函数

 let teststr="abcdefg";
 console.log(teststr.fontsize("16px")) //<font size="16px">abcdefg</font>

(method) String.fontcolor(color: string): string
Returns a HTML element and sets the color attribute value

次函数接收一个string并且返回一个font html elment将传入 的string设置为font标签的size属性

String.includes()函数

 let teststr="abcdefg";
 console.log(teststr.includes('bcd'))// true
 console.log(teststr.includes('bcd',2))// false

(method) String.includes(searchString: string, position?: number): boolean
Returns true if searchString appears as a substring of the result of converting this object to a String, at one or more positions that are greater than or equal to position; otherwise, returns false.
@param searchString — search string
@param position — If position is undefined, 0 is assumed, so as to search all of the String…

此函数接受两个参数,第一个参数指的是要查询的字符串,第二个参数指的的需要查询的起始位置。
若查询到则返回true,否则false。

String.indexOf()函数

 let teststr="abcdefg";
 console.log(teststr.indexOf("bcd"))// 1
  console.log(teststr.indexOf("bcd",1))// 1
 console.log(teststr.indexOf('bcd',2))// -1

(method) String.includes(searchString: string, position?: number): boolean
Returns true if searchString appears as a substring of the result of converting this object to a String, at one or more positions that are greater than or equal to position; otherwise, returns false.
@param searchString — search string
@param position — If position is undefined, 0 is assumed, so as to search all of the String…

此函数接受两个参数,第一个参数指的是要查询的字符串,第二个参数指的的需要查询的起始位置。
若查询到则返回目标字符串在当前字符串查询到的第一个结果起始的下标,否则返回-1。

String.italics()函数

 let teststr="abcdefg";
 console.log(teststr.italics())//<i>abcdefg</i>

(method) String.italics(): string
Returns an i HTML element
此函数没有参数,直接讲string标签返回成i element

String.lastIndexOf()函数

 let teststr="abcdefgabcdefg";
 console.log(teststr.lastIndexOf("bcd"))// 8
  console.log(teststr.lastIndexOf("bcd",1))// 8
 console.log(teststr.lastIndexOf('bcd',9))// -1

(method) String.lastIndexOf(searchString: string, position?: number): number
Returns the last occurrence of a substring in the string.
@param searchString — The substring to search for.
@param position — The index at which to begin searching. If omitted, the search begins at the end of the string.

此函数接受两个参数,第一个参数指的是要查询的字符串,第二个参数指的的需要查询的起始位置。
若查询到则返回目标字符串在当前字符串查询到的最后结果起始的下标,否则返回-1。

String.link()函数

 let teststr="abcdefg";
 console.log(teststr.link("Aname"))//<a href="http://www.baidu.com">abcdefgabcdefg</a>

Returns an a HTML anchor element and sets the name attribute to the text value
函数解释的是将字符串的内容包装成a便签的elemnet并且可以传入一个字符串设置a标签的超链接地址 href属性的内容。

String.split()函数

 let test="abcabcabcabcdef";
let b=test.split("b");
console.log(b);//[ 'a', 'ca', 'ca', 'ca', 'cdef' ]
b=test.split("b",2);
console.log(b);//[ 'a', 'ca' ]

(method) String.split(separator: string | RegExp, limit?: number): string[] (+1 overload)
Split a string into substrings using the specified separator and return them as an array.
@param separator — A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
@param limit — A value used to limit the number of elements returned in the array.

此函数有两个参数,第一个参数必选,可传入一个正则表达式或则一个字符串。以传入的字符进行分割。并返回一个切割好的字符串数组。第二个参数是限制返回的字符串的长度,大于限制的长度则不予返回。

String.reverse()函数

 let test="abcabcabcabcdef";
let b=test.split("b").reverse();
console.log(b);//[ 'f', 'e', 'd', 'c', 'b', 'a', 'c', 'b', 'a', 'c', 'b', 'a', 'c', 'b', 'a' ]

(method) Array.reverse(): string[]
Reverses the elements in an Array.

将当前数组倒序传出。

String.join()函数

 let test="abcabcabcabcdef";
let b=test.split("b").reverse().join('');
console.log(b);//fedcbacbacbacba

(method) Array.join(separator?: string): string
Adds all the elements of an array separated by the specified separator string.
@param separator — A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.

此函数接受一个string类型的参数,将当前数组用传入的string进行拼接。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值