一、数组转字符串

需要将数组元素用某个字符连接成字符串,示例代码如下

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>数组转化为字符串</title>
</head>
<body>
<script type="text/javascript">
var a, b,c;
a = new Array(11,22,33,44,55);
b = a.join('-');
c = a.join('');
document.writeln(a.constructor);//输出:function Array() { [native code] }
document.writeln(b);//11-22-33-44-55 使用-拼接数组元素
document.writeln(c);//1122334455
</script>
</body>
</html>

二、字符串转化为数组:

实现方法为将字符串按某个字符切割成若干个字符串,并以数组形式返回,示例代码如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>字符串转化为数组</title>
</head> <body>
<script type="text/javascript">
var str = 'ab+c+de';
var a = str.split('+');
var b = str.split('');
document.writeln(a);// [ab, c, de]
document.writeln(b);//[a, b, +, c, +, d, e]
</script>
</body>
</html>

js数组与字符串之间的相互转换的更多相关文章

  1. Golang 数组和字符串之间的相互转换[]byte/string

    package main import ( "fmt" ) func main() { str := "hello" arr := []byte(str) fm ...

  2. Json数组操作小记 及 JSON对象和字符串之间的相互转换

    [{"productid":"1","sortindex":"2"},{"productid":&q ...

  3. JS中实现JSON对象和JSON字符串之间的相互转换

    对于主流的浏览器(比如:firefox,chrome,opera,safari,ie8+),浏览器自己提供了JSON对象,其中的parse和stringify方法实现了JSON对象和JSON字符串之间 ...

  4. JSON对象与字符串之间的相互转换

    <html> <head> <meta name="viewport" content="width=device-width" ...

  5. JSON对象与字符串之间的相互转换 - CSDN博客

    原文:JSON对象与字符串之间的相互转换 - CSDN博客 <html> <head> <meta name="viewport" content=& ...

  6. strconv:各种数据类型和字符串之间的相互转换

    介绍 strconv包实现了基本数据类型和其对应字符串之间的相互转换.主要有一下常用函数:Atoi,Itoa,Parse系列,Formart系列,Append系列 string和int之间的转换 这一 ...

  7. JavaScriptES6中Map与对象、数组,JSON之间的相互转换

    JavaScriptES6中Map与对象.数组,JSON之间的相互转换 https://blog.csdn.net/c__dreamer/article/details/82183130

  8. js数组与字符串的相互转换方法 数组常用的方法

    1 数组转字符串 需要将数组元素用某个字符连接成字符串,示例代码如下: var a, b; a = new Array(0,1,2,3,4); b = a.join("-"); 二 ...

  9. js数组与字符串的相互转换方法

    一.数组转字符串 需要将数组元素用某个字符连接成字符串,示例代码如下: var a, b; a = new Array(0,1,2,3,4); b = a.join("-"); 二 ...

随机推荐

  1. VC++ 利用CreateFile、ReadFile和WriteFile实现CopyFile

    1. CreateFile:这是一个多功能的函数,可打开或创建以下对象,并返回可访问的句柄:控制台,通信资源,目录(只读打开),磁盘驱动器,文件,邮槽,管道. 参照:http://www.cppblo ...

  2. SQLSERVER 数据从一张那个表复制到另一张表

    insert into 表名1 ( 字段A ,字段B ,字段C) SELECT 字段A ,字段B ,字段C FROM 表名2 (where条件看情况而定)

  3. 【LTE基础知识】SGLTE, SVLTE, CSFB, VoLTE【转】

    本文转载自:https://blog.csdn.net/henryghx/article/details/18416405 4G网络下实现语音通话功能的技术共有三种——VoLTE.SGLTE(GSM ...

  4. 【第二十六章】 hystrix-dashboard + turbine

    一.使用turbine的意义 引入多个hystrix stream: 1.使用hystrix-dashboard的可以添加多个stream的功能 图中添加的两个stream会在真正monitor的时候 ...

  5. ovs-ofctl: s1 is not a bridge or a socket 解决方法

    参考: ovs-vsctl: Error detected while setting up bridge ovs-ofctl: s1 is not a bridge or a socket 解决方法 ...

  6. 机器学习-数据可视化神器matplotlib学习之路(四)

    今天画一下3D图像,首先的另外引用一个包 from mpl_toolkits.mplot3d import Axes3D,接下来画一个球体,首先来看看球体的参数方程吧 (0≤θ≤2π,0≤φ≤π) 然 ...

  7. 【Python】【有趣的模块】【Bobo】

    [python web框架之 bobo的安装配置] [Mac] 我的Mac环境,python3.5 1. 安装bobo  :   >>> pip3 install bobo 2. 配 ...

  8. poj 2480 Longge's problem 欧拉函数+素数打表

    Longge's problem   Description Longge is good at mathematics and he likes to think about hard mathem ...

  9. IDEA Spring-boot-devTools 无效解决办法二

    转载地址:Intellij IDEA 使用Spring-boot-devTools无效解决办法 相信大部分使用Intellij的同学都会遇到这个问题,即使项目使用了spring-boot-devtoo ...

  10. shell 判断字符串是否为空

    #!/bin/bash a="" if [ -n "$a" ] then echo "-n $a : 字符串长度不为 0" else ech ...