当前位置:网站首页>ES6 new method
ES6 new method
2022-07-27 19:07:00 【qq_ forty-two million forty-two thousand one hundred and fifty-】
One 、includes
Determine whether the string contains some characters , Or whether the array contains an element
1、 Basic usage
console.log('abc'.includes('a'));//true
console.log('abc'.includes('d'));//false
console.log([1,2,3].includes(1));//true
console.log([1,2,3].includes('1'));//false
2、 The second parameter
Indicates where to start the search , The default is 0
console.log('abc'.includes('a',1));//false
Two 、padStart() and padEnd()
Complete the length of the string
1、 Basic usage
console.log('x'.padStart(5,'ab'));//ababx
console.log('x'.padEnd(5,'ab'));//xabab
2、 matters needing attention
- The length of the original string , Equal to or greater than the maximum length , The original string will not be subtracted , String completion does not take effect , Returns the original string
console.log('xxx'.padEnd(2,'ab'));//xxx
- The sum of the length of the complement string and the original string exceeds the maximum length , Truncate the complement string exceeding the number of digits , The original string does not move
console.log('abc'.padStart(10, '0123456789'));//0123456abc
- If you omit the second parameter , By default, space is used to complete the length
3、 ... and 、trimStart() and trimEnd()
Clear the space at the beginning or end of the string , The space in the middle will not be cleared
Four 、 Array of Array.from()
Convert other data types to arrays
All traversable
Array 、 character string 、Set、Map、riodeList、arguments
Have length Property
1、 Basic usage
console.log(Array.from('str'));//[ 's', 't', 'r' ]
const obj = {
'0':'a',
'1':'b',
name: 'Alex',
length: 3
};
console.log(Array.from(obj));//[ 'a', 'b', undefined ]
2、 The second parameter
Act like an array map Method , Used to process each element , Put the processed value into the returned array
console.log(
[1,2].map(value => {
return value * 2})
);//[ 2, 4 ]
console.log(Array.from('12', value => value * 2));//[ 2, 4 ]
5、 ... and 、find() and findIndex()
find(): Find an immediate return that meets the conditions
findIndex(): Find one that meets the conditions , Return to an index immediately
1、 Basic usage
console.log(
[1,5,10,15].find((value) =>{
return value > 9;
})
);//10
console.log(
[1,5,10,15].findIndex((value) =>{
return value > 9;
})
);//2
6、 ... and 、Object.assign()
Merge objects
The following of the same attribute will overwrite the previous
You can merge multiple objects
const apple = {
color: ' Red ',
shape: ' circular ',
taste: ' sweet '
};
const pen = {
color: ' black ',
shape: ' cylindrical ',
use: ' Write '
};
console.log(Object.assign(apple,pen));
//{ color: ' black ', shape: ' cylindrical ', taste: ' sweet ', use: ' Write ' }
console.log(apple)//{ color: ' black ', shape: ' cylindrical ', taste: ' sweet ', use: ' Write ' }
console.log(Object.assign(apple,pen)===apple)//true
7、 ... and 、Object.keys). Object.values() and Object.entries()
Get the key value of the object
const person = {
name: 'Alex',
age: 18
};
console.log(Object.keys(person));//[ 'name', 'age' ]
console.log(Object.values(person));//[ 'Alex', 18 ]
console.log(Object.entries(person));//[ [ 'name', 'Alex' ], [ 'age', 18 ] ]
边栏推荐
- Extension of ES6 value
- 用Matlab生成适用于期刊及会议的图形- plot
- SQL server stored procedures multi angle introduction suggestions collection
- C interface knowledge collection suggestions collection
- Questions about webservice
- Kinect for Unity3d----KinectManager
- 电磁场学习笔记-矢量分析和场论基础
- Kinect2 for unity3d - avatardemo learning
- Collection of software design suggestions of "high cohesion and low coupling"
- Low noise anion fan touch IC
猜你喜欢

Selenium automated test interview questions family bucket

Self control principle learning notes - system stability analysis (2) - loop analysis and Nyquist bode criterion

Unity学习笔记(实现传送带)

The understanding of string in C.

Kinect2 for unity3d - avatardemo learning

Led learning eye protection table lamp touch chip-dlt8t10s-jericho

Music rhythm colorful gradient lamp chip -- dlt8s04a- Jericho

express

Big enemies, how to correctly choose the intended enterprises in the new testing industry?

MySQL 02 initial experience
随机推荐
WinForm screenshot save C code
Kinect for Unity3D——BackgroundRemovalDemo学习
JDBC-MySql 01 JDBC操作MySql(增删改查)
微机原理学习笔记-常见寻址方式
Useful resources for ns2
asp.net 的经验
MySQL 05 stored procedure
Nodejs template engine EJS
MySQL 02 initial experience
`this.$ Emit ` the child component passes multiple parameters to the parent component
收下这份实操案例,还怕不会用Jmeter接口测试工具
怎样产生标准分布或高斯分布的随机数
IDEA成功连接Database但不显示表怎么办
Electric heating neck pillow chip-dltap703sc
Introduction to assembly language (1)
Unity learning notes - six common functions of object movement
大冤种们,新进测试行业,如何正确选择意向企业?
一篇让你掌握线程和线程池,还解决了线程安全问题,确定不看看?
Kinect2 for unity3d - avatardemo learning
Latex使用-控制表格或者图形的显示位置