2
To illustrate the degree of difficulty, I place 3 div
and within them identical words, purposeful to add their duplication.
<div> <div> <div> Diego Ademir Diego Maicon Diego Maicon Adriana Maicon Ademir Magda Adriana Adriana Delvair Magda Ademir Roselene Delvair Delvair Lawiny Ademir Lawiny Nicolas Lawiny Roselene Alice Nicolas Nicolas Ademir Alice Alice Júlia Júlia Ademir </div> </div> </div>
I want to go through all three div
with for
and, returns the total number of repetition of the name "Ademir" in the alert
. See an example with array
:
var y = ["Diego","Maicon","Ademir","Adriana","Ademir","Delvair","Lawiny","Roselene","Nicolas","Alice","Ademir"];
var objects= {};
for (var x in y) {
objects[y[x]] = objects[y[x]]!=undefined ? objects[y[x]]+1 : 1;
}
alert("Encontramos " + objects.Ademir + " repetição do nome 'Ademir'!");
Based on the example given, I wish to make with the div
and add each identical word found within the 3 div
, and returns its total.
Remembering that, for the word in which it should be searched/summed is the name "Ademir".
You use angular in your project ?
– Pablo Dias
@phdias No, only pure Javascript.
– Diego Henrique
Diego, are the divs inside each other? Because if the whole content is only in the inner div of your question, or it’s like <div>João</div><div>Maria</div> ....
– Mathiasfc
Diego, post the Divs HTML code that makes it easier to point out an assertive solution
– andrepaulo
@Mathias No, they’re free. Like what you mentioned
<div>João</div><div>Maria</div>
....– Diego Henrique
@andrepaulo Observe as 3
div
on the question. That’s all I have.– Diego Henrique