当前位置:网站首页>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 ] ]
边栏推荐
- Collection of software design suggestions of "high cohesion and low coupling"
- 「测试新手百科」5 分钟快速上手Pytest 自动化测试框架
- Day 3 of leetcode question brushing
- Kinect for Unity3d----KinectManager
- How to break the team with automated testing
- WSN journal indexed by SCI
- Whole body multifunctional massage instrument chip-dltap602sd
- Code interview of Amazon
- NPM basic use
- Leetcode first day of question brushing
猜你喜欢

MySQL 01 关系型数据库设计

Whole body multifunctional massage instrument chip-dltap602sd

Unity显示Kinect捕获的镜头

MongoDB

The understanding of string in C.

Typescript installation

Music rhythm colorful gradient lamp chip -- dlt8s04a- Jericho
![[wechat applet] project practice - lottery application](/img/08/1e8643c95ad7c2661a76f9c3a0c57d.png)
[wechat applet] project practice - lottery application

web UI 自动化测试:Selenium 语法详解 史上最全

Unity学习笔记(实现传送带)
随机推荐
Kinect for Unity3d----KinectManager
MySQL 05 stored procedure
Latex使用--subfigure竖排图形
电磁场学习笔记-矢量分析和场论基础
MongoDB
2022备战秋招10W字面试小抄pdf版,附操作系统、计算机网络面试题
An article allows you to master threads and thread pools, and also solves thread safety problems. Are you sure you want to take a look?
Blog Garden beautification tutorial
MicaZ+Tinyos学习笔记(1)
换行问题双保险
正则表达式的扩展
Introduction to assembly language (1)
一个经验
MongoDB
The great idea of NS2
C#与Mysql数据库交互-Mysql配置及增删查改操作
webservice的疑问
Imitation thread deduction
Unity学习笔记——物体移动六种常见函数
express get/post/delete...请求