原型 - uniq() 方法
此方法生成一个数组的无重复版本。如果没有找到重复,则返回原始数组。
语法
array.uniq();
返回值
返回一个无重复元素的新数组。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var arr = ['Sam', 'Justin', 'Andrew', 'Dan', 'Sam'];
alert("Old Array : " + arr.inspect() );
alert("New Array : " + arr.uniq().inspect() );
}
</script>
</head>
<body>
<p>Click the button to see the result.</p>
<br />
<br />
<input type = "button" value = "Result" onclick = "showResult();"/>
</body>
</html>
输出
prototype_array_processing.htm
广告