JavaScript配列要素が重い
890 ワード
配列内の重複要素を削除:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd
">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
<title>Insert title here</title>
</head>
<body>
<input type="button" value=" " onclick="test();" />
</body>
<script type="text/javascript">
function clearArrayDulplicate(dulplicateArray){
var array = [];
for(var i=0;i<dulplicateArray.length;i++){
if(array.indexOf(dulplicateArray[i])<0){
array.push(dulplicateArray[i]);
}
}
return array;
};
function test(){
var array = [1,2,5,3,1,4,2,1,5,9,12];
var newArray = clearArrayDulplicate(array);
alert(newArray);
};
</script>
</html>