www.kbqf.net > js 数组变字符串

js 数组变字符串

var str = "aaa,bbb,ccc";var arr = str.split(',');//检测是不是数组的实例console.log(arr instanceof Array);//true搞定

var str = "abcd" str.split("")

用JSON.stringify方法: var arr=[1,2,3];var str=JSON.stringify(arr);//结果为:"[1,2,3]"var arr1=JSON.parse(str);//把字符解析为数组

数组与字符串的相互转化 var obj="new1abcdefg".replace(/(.)(?=[^$])/g,"$1,").split(","); //字符串转化为数组 var obj2 = "new2abcdefg".split(""); //字符串转化为数组 alert(obj); alert(obj.length); alert(obj instanceof Array); alert(...

var b = eval('(' + txtResult.value + ')');

可以用数组的字符串拼接函数join(),例如 var arr = ["12", "34", "56"]; alert(arr.join("")); // join的参数是分隔符

var a = [1,2,3]; alert(a.join()); alert(a.join("")); var b = ['1','2','3']; alert(b.join(""));

var arr = [ 1,2,3,4,5,6,7];console.log(JSON.stringify(arr));

var a, b;a = new Array(0,1,2,3,4);b = a.join("-");

网站地图

All rights reserved Powered by www.kbqf.net

copyright ©right 2010-2021。
www.kbqf.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com