I have an array containing elements .
What I want is to count the no. of elements every time when the Set Interval function loads in javascript.
Something like a counter but when I am using the count function it's displaying an error :
Uncaught TypeError: x.count is not a function
I just want to count the no. of values when setinterval function occurs every time starting from 0 .
Here is the Code :
var countArray = ["2020-14-03 11:14:48.225000","2020-14-03 11:14:48.226000","2020-14-03 11:14:48.227000","2020-14-03 11:14:48.228000","2020-14-03 11:14:48.229000","2020-14-03 11:14:48.230000","2020-14-03 11:14:48.231000","2020-14-03 11:14:48.232000","2020-14-03 11:14:48.233000","2020-14-03 11:14:48.234000","2020-14-03 11:14:48.235000","2020-14-03 11:14:48.236000","2020-14-03 11:14:48.237000","2020-14-03 11:14:48.238000","2020-14-03 11:14:48.239000","2020-14-03 11:14:48.240000","2020-14-03 11:14:48.241000","2020-14-03 11:14:48.242000","2020-14-03 11:14:48.243000","2020-14-03 11:14:48.244000"];
console.log(countArray.length);
var j = 0;
function countval() {
return countArray[j++];
}
setInterval(function() {
var counter = 0;
x = countval();
console.log("X value: ", x);
counter = x.count();
console.log("Count: ", counter);
}, 1000);
for example: console.log("Count: ", counter);
should print:
0
1
2
3
4
5
6
7
8
9
after each second.
Update: My queston is of string format. how so I want to count the no. of string elements occurence in an array.