📅  最后修改于: 2020-10-25 10:47:08             🧑  作者: Mango
在ES6中添加到String对象的一些流行方法是-
Sr.No | Method & Description |
---|---|
1 |
str.startsWith(searchString[, position])
determines whether a string begins with the characters of a specified string. Returns true or false |
2 |
str.endsWith(searchString[, length])
determines whether a string ends with the characters of a specified string. Returns true/false |
3 |
str.includes(searchString[, position])
determines whether one string may be found within another string |
4 |
str.repeat(count)
constructs and returns a new string which contains the specified number of copies of the string on which it was called, concatenated together |
在正则表达式中,例如/ [AZ] / g ,开始和结束/称为定界符。结束定界符之后的任何内容都称为修饰符。 ES6添加了一个新的修饰符/ g ,其中g代表global 。这将匹配字符串模式的所有实例,而不仅仅是一个。
以下示例搜索并返回字符串所有大写字符。
上面代码的输出如下:
["J", "J", "F", "W", "F"]
正则表达式搜索区分大小写。若要关闭区分大小写,请使用/ i修饰符。
以下示例执行不区分大小写的全局匹配。该示例将乐趣替换为愉快。
上面代码的输出将如下所示-
Javascript is enjoyable to Work , very enjoyable
Javascript is fun to Work , very Fun
15
在ES6中添加到Number对象的一些流行方法是-
Sr.No | Method & Description |
---|---|
1 |
Number.isFinite(value)
method determines whether the passed value is a finite number. Returns true/false. |
2 |
Number.isNaN(value)
returns true if the given value is NaN and its type is Number; otherwise, false. |
3 |
Number.parseFloat(string)
A floating-point number parsed from the given value. If the value cannot be converted to a number, NaN is returned. |
4 |
Number.parseInt(string,[ radix])
method parses a string argument and returns an integer of the specified radix or base. |
在ES6中添加到Math对象的一些流行方法是-
Sr.No | Method & Description |
---|---|
1 |
Math.sign()
function returns the sign of a number, indicating whether the number is positive, negative or zero. |
2 |
Math.trunc()
function returns the integer part of a number by removing any fractional digits. |
下表给出了ES6中不同的数组方法及其说明。
Sr.No | Method & Description |
---|---|
1 |
copyWithin()
shallow copies part of an array to another location in the same array and returns it without modifying its length. |
2 |
entries()
method returns a new Array Iterator object that contains the key/value pairs for each index in the array. |
3 |
find()
method returns the value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned.. |
4 |
fill()
method fills all the elements of an array from a start index to an end index with a static value. It returns the modified array. |
5 |
Array.of()
method creates a new Array instance from a variable number of arguments, regardless of number or type of the arguments. |
6 |
Array.from()
method creates a shallow copy from an array like or iterable object. |
下表中提及了与对象函数有关的方法以及相应的说明。
Sr.No | Method & Description |
---|---|
1 |
Object.is()
method determines whether two values are the same value |
2 |
Object.setPrototypeOf()
method sets the prototype of a specified object to another object or null. |
3 |
Object.assign()
method is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object. |