当前位置:网站首页>ES6 new method
ES6 new method
2022-04-23 17:41:00 【KK should continue to work hard】
ES6 The new method
includes()
Format :arr.includes( Find value , Where to start searching )
// Find the corresponding value and return true, Otherwise return to false
'abc'.includes('a')
padStart() and padEnd()
Format :str.padStart( The total number of digits in the string , Add the corresponding string )/padEnd( The total number of digits in the string , Add string )
// Once upon a time, I began to complete the string
'x'.padStart(5,'ab') //ababx
// Complete the string from after
'x'.padEnd(5,'ab') //xabab
Be careful :
- The length of the original string is 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 ;
- 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 ;
- If you omit the second parameter , By default, space is used to complete the length
trimStart()/trimLeft() And trimEnd()/trimRight()
Format :str. trimStart()
// Remove the space on the left , No removal in the middle
' x y'.padStart()/trimLeft() //x y
// Remove the space on the right , No removal in the middle
'x '.padEnd()/trimRight() //x
Array.from()
Format :Array.from( data , Data manipulation ,this Point to )
// Convert other data types to arrays
console.log(Array.from('hello')); //['h','e','l','l','o']
// Have length Property
// Key names can only be indexes
const obj = {
'0': 'xxx',
'1': 18,
length: 2
}
console.log(Array.from(obj))
console.log(Array.from('12', (value)=>value*2) //[2,4]
find()
Format :arr.find(function(value, index, arr){},this Point to )
// Find a value that meets the criteria and return immediately
[1,2,3,4].find((value)=>value>2)
findIndex()
Format :arr.findIndex(function(value, index, arr){},this Point to )
// Find a value that matches the criteria , Return the index of this value to
[1,2,3,4].findIndex((value)=>value>2)
Object.assign()
Format :Object.assign(obj1, obj2)
// Merge objects , Merge directly into the first parameter , Returns the merged object
const obj1 = {
name: 'xxx',
age: 18
}
const obj2 = {
name: 'yyy',
age: 18,
sex: 'male'
}
Object.assign(obj1, obj2); //{name:'yyy', age: 18, sex: 'male'}
Object.keys()、Object.values() And Object.entries()
const obj = {
username: 'yyy',
age: 18,
sex: 'female'
}
console.log(Object.keys(obj2)); //['username', 'age', 'sex']
Object The difference between the three methods and the three methods of array : Array of keys、values、entries It's an instance method , All of them iterator; Object's keys、values、entries Is a constructor method , It's an array
版权声明
本文为[KK should continue to work hard]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230551363651.html
边栏推荐
- Clickhouse SQL operation
- C dapper basically uses addition, deletion, modification and query transactions, etc
- Model problems of stock in and stock out and inventory system
- Solution of Navicat connecting Oracle library is not loaded
- 48. Rotate image
- [logical fallacy in life] Scarecrow fallacy and inability to refute are not proof
- Understanding and small examples of unity3d object pool
- JVM class loading mechanism
- Dry goods | how to extract thumbnails quickly?
- STM32 entry development board choose wildfire or punctual atom?
猜你喜欢
随机推荐
Self use learning notes - connectingstring configuration
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
Websocket (basic)
Manually implement call, apply and bind functions
Advantages and disadvantages of several note taking software
JVM class loading mechanism
31. Next arrangement
2. Electron's HelloWorld
92. 反转链表 II-字节跳动高频题
2021长城杯WP
Ring back to origin problem - byte jumping high frequency problem
[二叉数] 二叉树的最大深度+N叉树的最大深度
239. 滑动窗口最大值(困难)-单向队列、大顶堆-字节跳动高频题
239. Maximum value of sliding window (difficult) - one-way queue, large top heap - byte skipping high frequency problem
[C] thoroughly understand the deep copy
Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
Use of shell awk command
Low code development platform sorting
Node template engine (EJS, art template)