"Rows":[
[0:"2017-01-01", 1:"Ontdekkingstocht"],
[0:"2017-01-01", 1:"Ontdekkingstocht"],
[0:"2017-01-02", 1:"Ontdekkingstocht"]]
How do I check if 0:"2017-01-01"
appears more than once, and if so, return true?
"Rows":[
[0:"2017-01-01", 1:"Ontdekkingstocht"],
[0:"2017-01-01", 1:"Ontdekkingstocht"],
[0:"2017-01-02", 1:"Ontdekkingstocht"]]
How do I check if 0:"2017-01-01"
appears more than once, and if so, return true?
Here's a fast way:
var data = {
"Rows": [
["2017-01-01", "Ontdekkingstocht"],
["2017-01-01", "Ontdekkingstocht"],
["2017-01-02", "Ontdekkingstocht"]
]
};
function dupes(data) {
var cnt = {};
data.Rows.forEach((i) => { cnt[i[0]] = 1 });
return Object.keys(cnt).length < data.Rows.length;
}
console.log(dupes(data));
Here a fonction doing that, with your array as parameter:
function checkDuplicate(arr){
var i = 0;
while(i < arr.length-1){
arr.slice(i+1).forEach(function(element) {
if(element[0] == arr[i][0])return true;
});
}
return false;
}
A fast readable way is:
const rows = [
["2017-01-01", "Ontdekkingstocht"],
["2017-01-01", "Ontdekkingstocht"],
["2017-01-02", "Ontdekkingstocht"]
];
const duplicates = rows
.reduce((prev, curr) => [...prev, ...curr])
.some((element, index, array) => array.filter(el => element === el));
console.log(duplicates);