前端JS:判断list(数组)中的json对象是否重复
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<script>
function displayDate(){
var arr = [{ d: ‘2015-10-12‘,C:‘Apple‘}, { d: ‘2015-10-12‘,C:‘Apple‘}, { d: ‘2015-10-13‘,C :‘Apple‘ }];
var find = false;
for (var i = 0; i < arr.length; i++) {
for (var j = i + 1; j < arr.length; j++) {
if (arr[i].d == arr[j].d && arr[i].C==arr[j].C) { find = true; break;}
}
if (find) break;
}
alert(find)
}
</script>
</head>
<body>
<h1>判断list中的json对象是否重复</h1>
<button type="button" onclick="displayDate()">是否重复</button>
</body>
</html>
原文地址:http://blog.51cto.com/59465168/2337946
时间: 2024-10-06 06:05:58