替换数组中某个元素
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
<script>
var a1="two";
var arr = [ "one", "two", "three", "four"];
var result="";
$.each(arr, function(){
var a=this;
if(a1==a){
return true;
}
result+=a+',';
});
result=result.substring(0,result.length-1);//去掉最后一个“,”
alert(result);
</script>
</body>
</html>
字符串转数组
如何把字符串"123,abc,xy,hi"转换成数组或者jQuery数组
var arr = '123,abc,xy,hi'.split(',');
for(var i in arr){
alert(arr[i])
}