js数组与字符串的相互转化

代码如下:

[pcsh lang="applescript" tab_size="4" message="" hl_lines="" provider="manual"]

<script type="text/javascript">
	//字符串转化为数组
	var obj="new1abcdefg".replace(/(.)(?=[^$])/g,"$1,").split(",");       
	//字符串转化为数组
	var obj2 = "new2abcdefg".split(""); 	
	alert(obj);
	alert(obj.length);
	alert(obj instanceof Array);
	//数组转化为字符串
	alert(obj.join(""));				
</script>

[/pcsh]

 

 

 

此处评论已关闭