js如何把字符串分割并转成数组

946 ℃

js如何把字符串分割并转成数组,下面web建站小编给大家详细介绍一下实现代码!

1、把字符串转数组

var str = 'Web site building tutorial'
console.log(str.split())
//['Web site building tutorial']

2、把字符串根据空格分割成数组

var str = 'Web site building tutorial'
console.log(str.split(' '))
//(4) ['Web', 'site', 'building', 'tutorial']

3、把字符串根据每个字符分割成数组

var str = 'Web site building tutorial'
console.log(str.split(''))
//(26) ['W', 'e', 'b', ' ', 's', 'i', 't', 'e', ' ', 'b', 'u', 'i', 'l', 'd', 'i', 'n', 'g', ' ', 't', 'u', 't', 'o', 'r', 'i', 'a', 'l']

js如何切割字符串(实现方法介绍)

js如何实现数组与字符串的相换

es6语法如何将字符串转为数组

php如何利用正则表达式将字符串转为数组

js如何获取文件名(附代码)

标签: split, 字符串转数组

上面是“js如何把字符串分割并转成数组”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_3138.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

生活小工具

收录了万年历、老黄历、八字智能排盘等100+款小工具!生活小工具
react如何实现滚动条(全部代码)
如何利用jQuery写一个倒计时
织梦网站文章生成目录层深结构缩短
如何利用nodejs做一个手机号注册功能
js从2个多维数组中取出不同的值重组