当前位置:网站首页>js中join方法
js中join方法
2022-07-26 20:29:00 【大象与小蚂蚁的生活】
js中的join方法
join方法用于把数组中的所有元素放入一个字符串。
元素是通过指定的分隔符进行分隔的。
大白话:join方法可以用符不同的分隔符来构建这个字串。join方法值接受一个参数,即用作分隔符的字符串,然后返回所有数组项的字符串。
var arr = ["red","yellow","blue"];
var array = [];

下面开始调用join方法
1、
array = arr.join(undefined);
console.log(array);
输出结果为: red,yellow,blue。
因为join方法的参数不传或者传入undefined会默认用逗号分隔。
2、
array = arr.join("|");
console.log(array);
输出结果为: red|yellow|blue。
join参数用是用"|"来分隔的
3、
array = arr.join(" | ");
console.log(array);
输出结果为: red | yellow | blue。
join参数使用" | "来分隔的,字符串是什么就用什么来分隔。
4、
console.log(Array.isArray(array));
console.log(typeof array);
输出结果为:false String
如果用join来分隔数组的话,这个变量就会变成字符串类型,就算之前是数组也会变成字符串类型。
5、
console.log(array.join(" | "));
输出结果报错: array.join is not a function
因为array现在已经变成了字符串了,而join只能数组来调用,所以报错!
边栏推荐
- 如何借助自动化工具落地DevOps|含低代码与DevOps应用实践
- Pointpillars: fast encoders for object detection from point clouds reading notes
- [英雄星球七月集训LeetCode解题日报] 第26日 并查集
- 基于Hough变换的直线检测(Matlab)
- 08_ UE4 advanced_ Start end pause menu UI
- Daily practice ----- there is a group of students' grades. Arrange them in descending order. To add a student's grade, insert it into the grade sequence and keep the descending order
- 【HCIA安全】NAT网络地址转换
- IT系统为什么需要可观测性?
- 每日练习------有一组学员的成绩,将它们按降序排列,要增加一个学员的成绩,将它插入成绩序列,并保持降序
- [hcie security] dual computer hot standby - primary and standby backup
猜你喜欢

4年软件测试工作经验,跳槽之后面试20余家公司的总结

2022开放原子全球开源峰会议程速递 | 7 月 27 日分论坛议程一览

Discussion on loan agreement mode with NFT as collateral

GOM and GEE lander list file encryption tutorial

SSM integration example

Apaas low code platform (I) | leave complexity to yourself and simplicity to users

微服务化解决文库下载业务问题实践

Retrieve the parameters in this method in idea for our use -- 1. Class diagram. 2. Double click shift

How to implement Devops with automation tools | including low code and Devops application practice

QT Foundation Day 1 (1) QT, GUI (graphical user interface) development
随机推荐
如何借助自动化工具落地DevOps|含低代码与DevOps应用实践
牛客多校-Journey-(建图distra+卡常优化)
Interceptors
SSM integration example
There are six ways to help you deal with the simpledateformat class, which is not a thread safety problem
Leetcode array class
TableWidget
Error in render: “TypeError: data.slice is not a function“
CFdiv1+2-Pathwalks-(树状数组+线性dp)
【HarmonyOS议题资料下载】HDD杭州站·线下沙龙专注应用创新 展现鸿蒙生态魅力
Mobile phone \ landline call forwarding setting method
播报语音 h5 SpeechSynthesisUtterance
JVM learning - memory structure - program counter & virtual machine stack & local method stack & heap & method area
Discussion on loan agreement mode with NFT as collateral
Practice of microservice in solving Library Download business problems
QT基础第一天 (1)QT,GUI(图形用户接口)开发
使用 LSTM 进行多变量时间序列预测--问题汇总
Ros2 node communication realizes zero copy
In the era of Web3.0, the technical theory of implementing a DAPP based on P2P DB
[英雄星球七月集训LeetCode解题日报] 第26日 并查集