0

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);
4
  • 1
    What did you try?
    – mykaf
    Commented Mar 7, 2024 at 16:48
  • I have not tried anything yet. I have been looking for some examples online but I have not been successful in finding anything that checks for a similar duplicate like in my array. I was hoping to get some dieas in here, but my question was closed. Commented Mar 7, 2024 at 17:20
  • 1
    SO isn't a coding service. How would you do this by hand? Think about that process and how you would translate it to JS
    – mykaf
    Commented Mar 7, 2024 at 17:23
  • My bad, sorry for the mistake. Commented Mar 7, 2024 at 18:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.