当前位置:网站首页>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 ] ]
边栏推荐
- Netred RGB mirror light touch chip-dlt8s15b-jericho
- normal distribution, lognormal distribution,正态随机数的生成
- MySQL 02 initial experience
- 用函数在Excel中从文本字符串提取数字
- 自控原理学习笔记-系统稳定性分析(1)-BIBO稳定及Routh判据
- 「测试新手百科」5 分钟快速上手Pytest 自动化测试框架
- Intelligent insomnia therapeutic instrument product dlt8p68sa Jericho
- Day 3 of leetcode question brushing
- Resource for NS2 beginner
- 电磁场学习笔记-矢量分析和场论基础
猜你喜欢

Leetcode brushes questions the next day

express get/post/delete...请求

NPM's ID card and dependence

Docker - docker installation, MySQL installation on docker, and project deployment on docker

Kinect for Unity3d----KinectManager

Unity shows Kinect captured shots

Day 3 of leetcode question brushing

SSM integration

npm的身份证和依赖

Bathroom with demister vanity mirror touch chip-dlt8t10s
随机推荐
Kinect for Unity3d----KinectManager
Sentinel1.8.4 persistent Nacos configuration
The understanding of string in C.
Day 3 of leetcode question brushing
Word 2007+ tips
SSM项目使用过滤器实现登录监听
C interface knowledge collection suggestions collection
JDBC MySQL 02 data access and Dao mode
Extension of regular expression
Extension of ES6 value
log4j. Properties log details
Low noise anion fan touch IC
Ruiji takeout SQL table
WPS turns off annoying advertisements
JDBC-MySql 01 JDBC操作MySql(增删改查)
MongoDB
C file and folder input / output stream code
贪心法,拟阵和亚模函数(refer)
Electromagnetic field learning notes - vector analysis and field theory foundation
USB rechargeable hand warmer chip dltap602sc Jericho