I had the below html table which consist of some rows .Among that I required to get the count of unique names for a Column "Company" .
Can any one please help me how can I do it either using java-script or Jquery.
var names = [];
var tds = document
.getElementById('customers')
.querySelectorAll("tr td:first-child");
for (var i=0; i < tds.length; ++i) {
var customer = tds[i].textContent;
if (names.indexOf(customer) == -1)
names.push(tds[i].textContent);
}
alert(names);
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
22 Points
68 Posts
How to get the Count of Unique values from html table column
Mar 22, 2018 06:52 PM|Beginer|LINK
Dear All,
I had the below html table which consist of some rows .Among that I required to get the count of unique names for a Column "Company" .
Can any one please help me how can I do it either using java-script or Jquery.
All-Star
48684 Points
11071 Posts
Re: How to get the Count of Unique values from html table column
Mar 23, 2018 01:12 AM|bruce (sqlwork.com)|LINK
in vanilla javascript:
or in more modern javascript:
Member
22 Points
68 Posts
Re: How to get the Count of Unique values from html table column
Mar 23, 2018 02:59 AM|Beginer|LINK
Sir,
Just added count++; and got the unique values But I a unable to find the way to implement the count++ in modern.js .Could you please help me in it
Star
8510 Points
2883 Posts
Re: How to get the Count of Unique values from html table column
Mar 23, 2018 03:12 AM|Cathy Zou|LINK
Hi Beginer
Working code as below:
Output:
Best regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
All-Star
48684 Points
11071 Posts
Re: How to get the Count of Unique values from html table column
Mar 23, 2018 03:15 PM|bruce (sqlwork.com)|LINK
the count is just:
names.length
note: javascript supports ++, but you broke the if by not adding {} when you make it multi-line.
also I like using hash map trick suggested. in vanilla javascript: