当前位置:网站首页>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'
边栏推荐
- 如何在 TiDB Cloud 上使用 Databricks 进行数据分析 | TiDB Cloud 使用指南
- Form for real-time custom verification
- How to add PDF virtual printer in win11
- 机器学习基础-决策树-12
- [embedded C foundation] Part 2: binary conversion and BCD coding
- Qt 信号和槽机制( 详解 )
- [embedded C foundation] Part 3: constants and variables
- 什么是事务及数据库的优化方法
- [Bi design teaching] STM32 and FreeRTOS realize low power consumption
- How to improve deep learning performance?
猜你喜欢
![[Bi design teaching] STM32 and FreeRTOS realize low power consumption](/img/2b/3af85135e08599aaa425698c0e83aa.png)
[Bi design teaching] STM32 and FreeRTOS realize low power consumption

企业数字化本质

Array, string de duplication

FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be depreca

Change password, confirm password verification antd

2020-12-13

Machine learning Basics - integrated learning-13

CTO of youhaoda, MVP of Huawei cloud, and Zhang Shanyou: build cloud native applications based on kubernetes and dapr

Chapter 6 提升

04 pyechars geographic chart (example code + effect diagram)
随机推荐
Black cat takes you to learn EMMC protocol chapter 27: what is EMMC's dynamic capacity?
Qt 信号和槽机制( 详解 )
Form for real-time custom verification
[embedded explanation] key scanning based on finite state machine and stm32
[embedded C foundation] Part 2: binary conversion and BCD coding
Machine learning Basics - integrated learning-13
企业数字化本质
CTO of youhaoda, MVP of Huawei cloud, and Zhang Shanyou: build cloud native applications based on kubernetes and dapr
[graduation design] oscilloscope design and Implementation Based on STM32 - single chip microcomputer Internet of things
The difference between sessionstorage, localstorage and cookies
Leetcode daily question (2196. create binary tree from descriptions)
Jetpack Compose 完全脱离 View 系统了吗?
How does kotlin help you avoid memory leaks?
[FPGA]: ISE generates MCS file and burning process
Storage model: big end and small end
Low code: reduce technical capability requirements and improve software development efficiency
拥有游戏的一部分,写在我的世界禁用NFT之后
Transaction of MySQL underlying principle (2)
Original juice multifunctional Juicer touch chip-dlt8t02s-jericho
Change the document type in endnode and import it in word