D3.js | d3.set.size() Function
The set.size() function in D3.js is used to count the number of unique elements and return the number of unique elements in the given array.
Syntax:
d3.set([Array]).size();
Parameters: This function accepts a parameter Array of strings.
Return Value: It returns the number of unique elements from the given array.
Below programs illustrate the d3.set.size() function in D3.js:
Example 1:
<!DOCTYPE html>
<html>
<head>
<title>d3.set.size() Function</title>
</head>
<body>
<script>
Array1 = [ "a" , "a" , "b" , "c" ];
Array2 = [ "c" , "c" , "c" ];
Array3 = [ "Geeks" , "gfg" , "GeeksforGeeks" ];
A = d3.set(Array1).size();
B = d3.set(Array2).size();
C = d3.set(Array3).size();
console.log(A);
console.log(B);
console.log(C);
</script>
</body>
|
Output:
3
1
3
Example 2:
<!DOCTYPE html>
<html>
<head>
<title>d3.set.size() Function</title>
</head>
<body>
<script>
A = d3.set([1, 2, 3, 3]).size();
B = d3.set([ "a" ]).size();
C = d3.set([ "a" , "b" , "c" , "a" , "b" , "c" ]).size();
console.log(A);
console.log(B);
console.log(C);
</script>
</body>
|
Output:
3
1
3
Ref: https://devdocs.io/d3~5/d3-collection#set_size
Last Updated :
28 Jun, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...