当前位置:网站首页>Es6--string (string)
Es6--string (string)
2022-07-16 05:54:00 【Like to drink pearl milk tea】
Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right
1. Identification of substrings
ES6 Before judging whether the string contains substrings , use indexOf Method ,ES6 A new method for identifying substrings is added
includes(): Returns a Boolean value , Determine if it is found Parameter string .
startsWith(): Returns a Boolean value , Judgment parameter string Whether it is at the head of the original string .
endsWith(): Returns a Boolean value , Judgment parameter string Whether it is at the end of the original string .
(1)includes( )
String.prototype.mytool=function(){
}
var str="hello"
var re=str.fontcolor("red")
var str="hello, Huaqing vision "
console.log(String.prototype)
var re1=str.includes(" Huaqing ")
var re2=str.includes(" ")
var re3=str.includes("")
console.log(re)Running results :
(2)startsWith( )、endWith( )
startsWith( 81,1): The positive number of the second parameter means the first one from front to back
var str="182828323410"
var str2=str.startsWith("81",1)
var str3=str.endsWith("2341",11)
console.log(str2,str3)Running results :

(3)repeat( )
repeat(): Returns a new string , Indicates that the string is repeated a specified number of times
repeat( ): There are no numbers in it , Output space
repeat( Numbers ): What is the number , Repeat several times
for example 1:
var str=" Huaqing vision "
var str2=str.repeat(2)
console.log(str2)Running results :

for example 2: All the elements in the number are used * Instead of
var str=" Huaqing vision 666"
var str2="*".repeat(str.length)
console.log(str2)Running results :

2.padEnd( )、padStart( ): String completion
It doesn't change the original array
padStart: Returns a new string , Parameter string for Complete the original string from the head .
padEnd: Returns a new string , Parameter string for Complete the original string from the tail .
The above two methods accept two parameters , The first parameter Is the specified build The minimum length of the string , The second parameter It's for Completed string . If The second parameter was not specified , Fill with space by default .
for example :
var str="99"
var str2=str.padEnd(6,"abc")
var str3=str.padStart(6,"abc")
console.log(str2,str3)Running results :

3. Template string
The template string is equivalent to the enhanced version of the string , Use back quotes `, Except as a normal string , just so so Used to define multiline strings , You can also add variables and expressions to a string


Running results :

边栏推荐
- [prettier] the code automatically formatted by prettier does not take effect
- [安洵杯 2019]easy_web
- Image source configuration of electron and electron Builder (2022-06)
- Steps for JS parsing engine to execute JS code
- Automatic deployment of server docking code cloud webhooks -- ultra detailed -- PHP
- Network security emergency response - basic skills
- Secondary development tutorial of fastadmin [simple construction, multi table problems, API development]
- Svelte official introductory tutorial (4) -- template logic
- Network security emergency response malicious code analysis technology
- WP of the southwest division of the 15th National College Students Information Security Competition (ciscn) 2022
猜你喜欢

36.js-- prototype chain 2-- (mainly written test questions)

BUUCTF 九连环
![[ASIS 2019]Unicorn shop](/img/e2/c295a83e03eeaa720a631f6d736eb2.png)
[ASIS 2019]Unicorn shop

Simply understand the three handshakes and four waves of TCP

Intranet penetration notes --:) a smiling face

内存取证-Volatility安装使用以及一些CTF比赛题目

网络安全应急响应-基础技能

ES6--Set

内网渗透笔记——:)一个笑脸

Network security emergency response terminal detection and response technology
随机推荐
Secondary development tutorial of fastadmin [simple construction, multi table problems, API development]
Notes - Chang Geng
Automatically generate a model (egg.js, which is generated by connecting with the database)
内网渗透笔记——粘滞键与系统命令信息收集
WP of the southwest division of the 15th National College Students Information Security Competition (ciscn) 2022
Intranet penetration notes - layer 2 Discovery
欧拉Talk | 开发者社区体验坦白局7月14日19:30约起
JS收官笔记
Image source configuration of electron and electron Builder (2022-06)
服务器对接码云webhooks实现自动部署--超详细--PHP
electron、electron-builder 镜像源配置(2022-06)
内网渗透笔记——三层发现and四层发现
[Huang ah code] getting started with MySQL - 1. SQL execution process
Sécurité des réseaux intervention d'urgence - technologie de collecte de données électroniques
php对接支付宝Web支付-tp5.1框架
7. Cache breakdown, cache penetration, cache
[Huang ah code] Microsoft Internet Explorer will be retired. Netizens said: what should I do in the future?
[Huang ah code] getting started with MySQL - 2. Using data definition language (DDL) to operate the database
Clues in buuctf packets
Collect form data