I have currently integrated a third-party API to visualize data using Highcharts.
This external API provides data specific to the current month, such as March, April, May, and so on.
graphArrOne
contains an array with 251 elements.
graphArrTwo
contains an array with 250 elements. graphArrayTwo
only includes data up until April, while graphArrayOne
extends up to May.
To handle this scenario, I am developing a conditional statement to compare both array lengths and remove the last element from the longer array if necessary.
My challenge lies in finding a way to delete the last element of an array dynamically without explicitly specifying its index. For instance, if the API updates and graphArrOne
now covers June while graphArrayTwo
stops at May, I still need to remove the last month's data.
Is there a method to remove the last element of an array without defining the exact index?
The desired outcome is to eliminate the last element from graphArrOne
if it has more elements than graphArrTwo
.
Here is my code snippet:
if (graphArrOne.length > graphArrTwo) {
graphArrOne.splice(-1,1); // This is what I'm attempting to accomplish.
}