Once removed duplicates, find the length of an array. I'm using the below code but it's returning 0
as the length of the array:
var mydata = ["1", "2", "3", "3", "4", "5", "5", "6", "7", "7", "8", "9", "9"];
var uniqueNames = [];
$(function() {
$.each(mydata, function(i, el) {
if ($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
});
})
console.log(uniqueNames.length);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Total length
13
Expected output
9
uniqueNames.length
? – Chris G Jun 13 '18 at 8:42length
property yet? Also, absolutely no need to require a large library like jQuery just for something like this, just usenew Set(myData).size
– CertainPerformance Jun 13 '18 at 8:43length = myData.filter((v, i, self) => { return self.indexOf(v) === i; }).length;
Codepen – fen1x Jun 13 '18 at 8:46