
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 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3138.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

帝国cms灵动标签调用字母所属的信息
2025年彻底抛弃app/小程序,网页也可以做客户端(具体操作方法)
佰腾专利检索网页版官网首页入口
玻尔官网:一个专注于科学研究的AI平台,科学家的AI文献助手