Javascript & JQuery & CSS > jQuery ¹è¿ Áߺ¹ Á¦°Å
µî·ÏÀÏ : 2017-07-04 19:36
Á¶È¸¼ö : 53,784
var test = ["2", "45", "7", "7", "21", "21", "45", "54", "54", "8", "5", "5", "44", "44", "5", "44"];
var arrDistinct = new Array();
$(document).ready(function() {
$(test).each(function(index, item) {
if ($.inArray(item, arrDistinct) == -1)
arrDistinct.push(item);
$("#container").append($("<li>").html(item));
});
$(arrDistinct).each(function(index, item) {
$("#distinct").append($("<li>").html(item));
});
});
======================================================================
function removeDuplicates(inputArray) {
var i;
var len = inputArray.length;
var outputArray = [];
var temp = {};
for (i = 0; i < len; i++) {
temp[inputArray[i]] = 0;
}
for (i in temp) {
outputArray.push(i);
}
return outputArray;
}
var inputArray = [1, 1, 4, 5, 6, 7, 7, 8, 8, 9, 8, 9, 8, 0, 6, 8, 4, 3, 5, 6];
//Output- 1,4,5,6,7,8,9,0,3
var ouputArray = removeDuplicates(inputArray);
alert(ouputArray);