I have the following array:
let items = [
{"Item":"1","OfficeID":"82388","Title":"Bamboozled"},
{"Item":"2","OfficeID":"82392","Title":"Malarkey"},
{"Item":"3","OfficeID":"65747","Title":"Flabbergasted"},
{"Item":"4","OfficeID":"82390","Title":"Cattywampus"},
{"Item":"5","OfficeID":"77091","Title":"Lollygag"},
{"Item":"6","OfficeID":"81726","Title":"Kerfuffle"},
{"Item":"7","OfficeID":"82155","Title":"Brouhaha"},
{"Item":"8","OfficeID":"82265","Title":"Skedaddle"},
{"Item":"8","OfficeID":"82394","Title":"Nincompoop"},
{"Item":"10","OfficeID":"82395","Title":"Tomfoolery"}
]
There is a repeated Item: 8
I would like to find the duplicate/repeated Item(s) value(s) so that I can use that information and return it to a message for the user. How can this be done using JavaScript. Any examples are appreciated.
Thank you
UPDATE
Work around to my problem. Adding it to this question, in the event that someone might have a smiliar question/issue, and lands in this forum.
const array = [
{"Agenda":"1","OfficeID":"82388","Title":"Bamboozled"},
{"Agenda":"2","OfficeID":"82392","Title":"Malarkey"},
{"Agenda":"3","OfficeID":"65747","Title":"Flabbergasted"},
{"Agenda":"4","OfficeID":"82390","Title":"Cattywampus"},
{"Agenda":"5","OfficeID":"77091","Title":"Lollygag"},
{"Agenda":"6","OfficeID":"81726","Title":"Kerfuffle"},
{"Agenda":"7","OfficeID":"82155","Title":"Brouhaha"},
{"Agenda":"8","OfficeID":"82265","Title":"Skedaddle"},
{"Agenda":"8","OfficeID":"82394","Title":"Nincompoop"},
{"Agenda":"10","OfficeID":"82395","Title":"Tomfoolery"}
];
const result = [];
let prevName = null;
let count = 0;
array.forEach(item => {
if (item.Agenda === prevName) {
count++;
} else {
if (count > 1) {
for (let i = 0; i < count; i++) {
result.push(prevName);
}
}
prevName = item.Agenda;
count = 1;
}
});
console.log('result:', result);