함수 multi array unique()

multi_array_unique()

1 JavaScript[ | ]

function multi_array_unique(arr) {
    var result = [];
    var dict = {};
    var len = arr.length;
    var k;
    for(var i=0; i<len; i++) {
        k = JSON.stringify(arr[i]);
        if( dict[k] ) continue;
        dict[k] = true;
        result.push( arr[i] );
    }
    return result;
}

var rows = [[1,2], [3,4], [1,2], [3,4]];
console.log( multi_array_unique(rows) );
// [[1, 2], [3, 4]]

var rows = [
	["102", "Yonezawa Akinori", "Naha, Okinawa"],
	["202", "Murata Makoto", "Sendai, Miyagi"],
	["102", "Yonezawa Akinori", "Naha, Okinawa"],
	["102", "Yonezawa Akinori", "Naha, Okinawa"]
];
console.log( multi_array_unique(rows) );
// [["102", "Yonezawa Akinori", "Naha, Okinawa"], ["202", "Murata Makoto", "Sendai, Miyagi"]]

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}