
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,我们会在看到邮件的第一时间内为您处理!

IT tools官网入口,一个专为开发人员和IT人员设计的在线工具
ComfyUI Z-Image I2L插件安装入口,ComfyUI自定义节点套件
推荐一款来自日本的高质量矢量图标素材网站——IFN(可免费商用)
一款大讯飞推出高效撰写各类文书材料的AI智能写作助手——讯飞文书
Semant Scholar AI:一个免费的科学文献搜索,包含超过 2.11 亿篇科学领域的论文