How to know that this is the last iteration of a function

162 views Asked by At

I am having the below function which represents X axis of a Chart.

Currently, in this function, 'n' has many iterations which present 0, 25, 50, depending upon the values selected dynamically.

Is there any possibility by which we can know if this is the last iteration of n?

xaxis: {showLabels: true, noTicks: 7,tickFormatter: function(n)
{
    var k = n;

    if(k==7) // This is not working
        return NewdateData[NewdateData.length-1]; 
    else  
        return NewdateData[k];      
}
1

There are 1 answers

4
Mic On

Reducing your function to a minimum works well comparing n with this.noTicks:

var xaxis = {showLabels: true, noTicks: 7,tickFormatter: function(n){
    return n === this.noTicks;
}};
console.log(xaxis.tickFormatter(1)); //false
console.log(xaxis.tickFormatter(7)); //true

Are you calling it the same way, ... .xaxis.tickFormatter(...) ?