Take only the repeated value of an Array

Asked

Viewed 32 times

0

I would like to take only names that repeat in an input array of type text.

For example: ['Daniel', 'Sarah', 'Mary', 'Daniel', 'Philip']

Return the 'Daniel''.

Follow the Assembly Code of the array and soon afterwards I would like to catch the repeat.

JS:

var mensagem = "";
var camposInput = new Array();

$("input[name='options2[]']").each(function () {      
    camposInput.push($(this).val());
});

console.log("Lista:", camposInput); // Retorna os nomes
console.log("Repetido:",?????); //Retonar o nome Repetido
  • It is not duplicate, I do not want to remove the repeated values, I that work with the repeated values

  • Danielle, the duplicate answer does not remove repeated values, it adds repeated values in an array without changing the original array.

  • @Sam Truth, Already get through the answer. Thank you

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.