当前位置:网站首页>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
边栏推荐
- 209. Minimum length subarray - sliding window
- In ancient Egypt and Greece, what base system was used in mathematics
- 209. 长度最小的子数组-滑动窗口
- Construction of functions in C language programming
- 92. 反转链表 II-字节跳动高频题
- Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
- 给 el-dialog 增加拖拽功能
- Halo open source project learning (II): entity classes and data tables
- 嵌入式系统中,FLASH中的程序代码必须搬到RAM中运行吗?
- .Net Core3. 1 use razorengine NETCORE production entity generator (MVC web version)
猜你喜欢

48. Rotate image

常用SQL语句总结
![SQL optimization for advanced learning of MySQL [insert, primary key, sort, group, page, count]](/img/60/e4d47d458dd98a0c6ba51874e07c30.png)
SQL optimization for advanced learning of MySQL [insert, primary key, sort, group, page, count]

01 - get to know the advantages of sketch sketch

Hcip fifth experiment

超分之TDAN

Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory

440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题

Simulation of infrared wireless communication based on 51 single chip microcomputer

If you start from zero according to the frame
随机推荐
STM32 entry development board choose wildfire or punctual atom?
Come out after a thousand calls
为什么有些人说单片机简单,我学起来这么吃力?
Use of five routing guards
Ouvrir des contrats à terme, ouvrir des comptes en nuage ou faire confiance aux logiciels des sociétés à terme?
剑指 Offer 03. 数组中重复的数字
209. 长度最小的子数组-滑动窗口
土地覆盖/利用数据产品下载
开期货,开户云安全还是相信期货公司的软件?
干货 | 快速抽取缩略图是怎么练成的?
Simulation of infrared wireless communication based on 51 single chip microcomputer
Metaprogramming, proxy and reflection
440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
Self use learning notes - connected and non connected access to database
How to use the input table one-way service to send (occupy less) picture files (body transmission)? FileReader built-in object involved
Read software engineering at Google (15)
How does matlab draw the curve of known formula and how does excel draw the function curve image?
Use of Shell sort command
Using quartz under. Net core -- operation transfer parameters of [3] operation and trigger
Use of shell cut command