Hey guys how can i check how many li is same in html using js | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hey guys how can i check how many li is same in html using js

<li>abcd</li> <li>efgh</li> <li>abcd</li> The output should be like abcd=2 , efgh=1

20th Oct 2021, 5:47 AM
Deepak Kanojiya
Deepak Kanojiya - avatar
4 Answers
+ 2
Is same in what way dude? same in its content, its style?. Elaborate more on that "is same" in the Description please ... (Edit) We can use an empty object to contain frequency counters https://code.sololearn.com/WVtxBbJ3i9rF/?ref=app
20th Oct 2021, 5:51 AM
Ipang
+ 2
Guys thanks for you help this made my work easy now Ipang and Stefanoo ๐Ÿ™โœŒ
22nd Oct 2021, 6:29 AM
Deepak Kanojiya
Deepak Kanojiya - avatar
+ 1
You could do something like this 1. create an dictionary with a string as key and a int as value 2. save the list(from html) into a variable 3. go through the list 4. check if the item is in your dictionary if not add it to it else increase the value by one 5. print the dictionary
20th Oct 2021, 6:23 AM
Stefanoo
Stefanoo - avatar
22nd Oct 2021, 6:11 AM
Ipang