JS数组去重: 已知数组 var array=[1,1,2,3,4,6,6,7,8,8,9],如
JS数组去重:已知数组vararray=[1,1,2,3,4,6,6,7,8,8,9],如何得到新的数组[1,2,3,4,6,7,8,9]...
JS数组去重:
已知数组 var array=[1,1,2,3,4,6,6,7,8,8,9],如何得到新的数组[1,2,3,4,6,7,8,9] 展开
已知数组 var array=[1,1,2,3,4,6,6,7,8,8,9],如何得到新的数组[1,2,3,4,6,7,8,9] 展开
展开全部
<html>
<head>
<title>我的第一个网页</title>
<script language="javascript" type="text/javascript">
function show(){
var array=[1,1,2,3,4,6,6,7,8,8,9];
var count = 0;
for(var i=0;i<array.length;i++){
if(i==array.length-1){
document.getElementById("arr").value+=array[i].toString();
}else{
document.getElementById("arr").value+=array[i].toString()+",";
}
}
for(var k=0;k<array.length;k++){
if(array[k]!=array[k+1]){
count++;
}
}
for(var j=0;j<array.length;j++){
if(j==array.length-1){
if(array[j]!=array[j+1]){
document.getElementById("newArr").value+=array[j].toString();
}
}else{
if(array[j]!=array[j+1]){
document.getElementById("newArr").value+=array[j].toString()+",";
}
}
}
}
</script>
</head>
<body onload="show()">
<table width="314">
<tr>
<td width="80">原数组:</td>
<td width="224"><input name="arr" type="text" id="arr" readonly="readonly" /></td>
</tr>
<tr>
<td>新数组:</td>
<td><input name="newArr" type="text" id="newArr" readonly="readonly" /></td>
</tr>
</table>
</body>
</html>
<head>
<title>我的第一个网页</title>
<script language="javascript" type="text/javascript">
function show(){
var array=[1,1,2,3,4,6,6,7,8,8,9];
var count = 0;
for(var i=0;i<array.length;i++){
if(i==array.length-1){
document.getElementById("arr").value+=array[i].toString();
}else{
document.getElementById("arr").value+=array[i].toString()+",";
}
}
for(var k=0;k<array.length;k++){
if(array[k]!=array[k+1]){
count++;
}
}
for(var j=0;j<array.length;j++){
if(j==array.length-1){
if(array[j]!=array[j+1]){
document.getElementById("newArr").value+=array[j].toString();
}
}else{
if(array[j]!=array[j+1]){
document.getElementById("newArr").value+=array[j].toString()+",";
}
}
}
}
</script>
</head>
<body onload="show()">
<table width="314">
<tr>
<td width="80">原数组:</td>
<td width="224"><input name="arr" type="text" id="arr" readonly="readonly" /></td>
</tr>
<tr>
<td>新数组:</td>
<td><input name="newArr" type="text" id="newArr" readonly="readonly" /></td>
</tr>
</table>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询