当前位置:网站首页>ES6 new - string part
ES6 new - string part
2022-07-27 09:10:00 【Cabbage 007】
1.es6 New template string The quotation marks - ``
es6 Previous string shortcomings
2.es6 New string instance method :
Static methods ( Non instance method ):
String extension
1.es6 New template string The quotation marks - ``
es6 Previous string shortcomings
stay es6 Previously, the declared string used single quotation marks or double quotation marks , Disadvantages of single and double quotation marks :
(1) You can't change lines casually (2)+ No. 1 splicing is cumbersome
New backquote benefits :
(1) Declare with a pair of backquotes : ` hello ` ; The backquote declaration type is also a string type
(2) Embed variables : You can embed any expression inside , grammar : ${ expression }
2.es6 New string instance method :
Static methods ( Non instance method ):
Constructor name . Method ( Parameters ) String.fromCharCode(10)
String instance method :
object / power . Method ( Parameters ) " aa ".split(" bb ")
Be careful : All instance methods of the string do not change the original string , Strings are read-only
(1)repeat(number) : Repeat the string a specified number of times and return , Round the decimal , Negative error str.repeat(2)
(2)startsWith(str,[startIndex = 0]) : Determine whether the string is a string start , Is to return true; no , return false
(3)endsWith(str,[endIndex = str.length - 1]) : Determine whether the string is a string ending , The optional parameter is subscript
(4)includes(str,[startIndex = 0]) : Determine whether a string contains a string , Include return true, Does not include return false
Can replace indexOf Method ,includes More semantically
(5)padStart(length,str) : String header padding , Returns the filled string , But it won't change the original string
(6)padEnd(length,str) : The end of the string is filled ,
length Represents the total length after filling ,length < str.length when , Will not do any filling , Returns the original string
(7)trimStart() : Remove the leading space of the string , Return the string after removing spaces
(8)trimEnd() : Remove the trailing space of the string
trim() : Remove the leading and trailing spaces of the string
(9)repalceAll(searchValue | searchPattern,replacement): String global substitution
repalce(): Only the first search result will be replaced
Use in different situations :
(1) Both parameters are strings :console.log(str.replace("a","b")) console.log(str.replaceAll("a","b"))
(2) The first parameter is regular , The second parameter is the string : console.log(str.replace(/a/g,"b")) // Equivalent to global replacement
console.log(str.replaceAll(/a/g,"b")) //replaceAll Regular no /g Will report a mistake
(3) The first parameter is regular , The second parameter is callback :
const str = "ccbbaa" ;
const ret = str.replace(/a/g,function(matchStr,index,str){
console.log(mathStr,index,str);
return " bb " }) // Output : "a" 5 "ccbbaa" ; "a" 6 "ccbbaa" // Print twice
console.log(ret)
Callback function parameters : first : Strings that conform to regular rules ; the second : Subscript in the original character ; Third : The original character itself
In a string , Space is also a space !!
边栏推荐
- Explain cache consistency and memory barrier
- 5G没能拉动行业发展,不仅运营商失望了,手机企业也失望了
- Sharing of four open source face recognition projects
- Deep understanding of Kalman filter (1): background knowledge
- NiO Summary - read and understand the whole NiO process
- Aruba学习笔记10-安全认证-Portal认证(web页面配置)
- PVT's spatial reduction attention (SRA)
- Linux Installation and remote connection MySQL records
- Full Permutation recursive thought sorting
- Qdoublevalidator does not take effect solution
猜你喜欢

“蔚来杯“2022牛客暑期多校训练营1

B tree

【ACL2020】一种新颖的成分句法树序列化方法

Explain cache consistency and memory barrier

Aruba learning notes 10 security authentication portal authentication (web page configuration)

Restful

The wechat installation package has soared from 0.5m to 260m. Why are our programs getting bigger and bigger?

Antdesign a-modal自定义指令实现拖拽放大缩小

Music experience ceiling! Emotional design details of 14 Netease cloud music

js call和apply
随机推荐
Two tips in arkui framework
Deep understanding of Kalman filter (2): one dimensional Kalman filter
[interprocess communication IPC] - semaphore learning
一些实用、常用、效率越来越高的 Kubernetes 别名
Matlab drawing skills and examples: stackedplot
NIO this.selector.select()
D3.v3.js data visualization -- pictures and tips of force oriented diagram
【云驻共创】华为云:全栈技术创新,深耕数字化,引领云原生
接口测试工具-Postman使用详解
Flex layout (actual Xiaomi official website)
PyTorch自定义CUDA算子教程与运行时间分析
Restful
Matlab求解微分代数方程 (DAE)
易语言编程: 让读屏软件可获取标签控件的文本
07_ Service registration and discovery summary
罗克韦尔AB PLC 通过RSLinx Classic与PLC建立通信的具体方法步骤
ctfshow 终极考核
Hangzhou E-Commerce Research Institute released an explanation of the new term "digital existence"
tensorflow包tf.keras模块构建和训练深度学习模型
如何注册码云账号