当前位置:网站首页>JS method of splitting strings
JS method of splitting strings
2022-07-28 13:17:00 【Pig Xiaoyong】
List of articles
js How to split strings
The applicable scenarios are different
const arr=['1-2','1-3','2-3','3-4'];
1、string.split()
With special character segmentation
'1-2'.split('-')
// ['1', '2']
2、String.substring(start,stop)
start It's necessary . A nonnegative integer , Specifies that the first character of the substring to be extracted is in string Position in .
stop Optional , A nonnegative integer , The head is not the tail , You need to add 1.
'hello'.substring(1,3)
// 'el'
3、 Use String.substr(start,lenght) Split string
start It's necessary . The starting subscript of the substring to extract . It must be a number . If it's a negative number , Then this parameter declares the position from the end of the string . in other words ,-1 Refers to the last character in the string ,-2 Refers to the penultimate character , And so on .
length Optional . The number of characters in the substring . It must be a number . If this parameter is omitted , Then return from string A string from the beginning to the end of .
'hello'.substr(1,3)
// 'ell'
4、 Use String.slice(start,end) Split string
Extract a part of the string , And return the extracted part with a new string .
'hello'.slice(1,3)
// 'el'
边栏推荐
- A brief introduction to the for loop. Some of the code involves arrays
- [Bi design teaching] STM32 and FreeRTOS realize low power consumption
- 03 pyechars rectangular coordinate system chart (example code + effect drawing)
- 【嵌入式C基础】第5篇:原码/反码/补码
- PCP parity principle arbitrage
- 企业数字化本质
- Change the document type in endnode and import it in word
- Code layered management of interface testing based on RF framework
- [embedded C foundation] Part 9: basic usage of C language pointer
- Automatic light sensing arm lamp touch chip-dlt8sa15b-jericho
猜你喜欢

【嵌入式C基础】第1篇:基本数据类型

【嵌入式C基础】第2篇:进制转换与BCD编码

Black cat takes you to learn EMMC Protocol Part 26: hardware reset operation of EMMC (h/w reset)

Shenwenbo, researcher of the Hundred Talents Program of Zhejiang University: kernel security in the container scenario

Leetcode daily question (2196. create binary tree from descriptions)

Ruan Bonan of Green Alliance Technology: cloud native security from the open source shooting range

Kotlin是如何帮助你避免内存泄漏的?

How does kotlin help you avoid memory leaks?

SSM框架网上书城全套

Unity—“合成大西瓜”小游戏笔记
随机推荐
子线程更新UI全解
Black cat takes you to learn EMMC Protocol Part 24: detailed explanation of EMMC bus test program (cmd19 & cmd14)
8、 Kubernetes network and load balancing
[embedded explanation] key scanning based on finite state machine and stm32
为什么说Crypto游戏正在改变游戏产业?
Original juice multifunctional Juicer touch chip-dlt8t02s-jericho
[embedded C foundation] Part 5: original code / inverse code / complement code
SQL most commonly used basic operation syntax
Mysql中DQL基本练习
【嵌入式C基础】第4篇:运算符的使用
Ruan Bonan of Green Alliance Technology: cloud native security from the open source shooting range
GameStop熊市杀入NFT交易,老牌游戏零售商借Web3焕发第二春
Huawei cloud Gao Hongxia: CBC microservice code Reconstruction & independent release practice
Protobuf data exchange format
With 433 remote control UV lamp touch chip-dlt8sa20a-jericho
Full disclosure! Huawei cloud distributed cloud native technology and Practice
Xampp Chinese tutorial guide
【C语言易错点】第4篇:结构体在内存中存储规则详讲
【嵌入式C基础】第3篇:常量和变量
LeetCode·每日一题·1331.数组序号转换·离散化