Having a Javascript array named full_range:
const range1 = _.range(1, 10, 0.5);
const range2 = _.range(10, 100, 5);
const range3 = _.range(100, 1000, 50);
const range4 = _.range(1000, 10000, 500);
const range5 = _.range(10000, 105000, 5000);
const full_range = range1.concat(range2).concat(range3).concat(range4).concat(range5);
A loop iterates over this array to fill another one.
var transY= [];
var transX= [];
for(let i = 0; i < full_range.length; i++){
let y = getTrans(full_range[i], dampingFactor, natFreq);
transY.push(y);
transX.push(parseFloat(full_range[i]));
}
The outcome is passed to another function where:
console.log(transX); //Shows Array of length 91 (decimals at the end)
console.log(transY); //Displays Array of length 91
console.log("first");
console.log(transX[0]); //Correctly displays 1
console.log("Last");
console.log(transX[-1]); //Incorrectly shows "undefined instead of the last item
let xd = transX.pop();
console.log("xd:" + xd); //Works as expected by printing the last item in transX
The objective is plotting this data on a BokehJS graph, which behaves strangely with undefined values.
Why does "undefined" act like an array element when using slicing, but not with pop()?
How can I retrieve the array without any undefined elements?