This is my first time facing multidimensional array.
I have an array of year like this:
yearArr = [
[2019, 2018, ''],
[2019, 2018, 2017],
['', 2018, 2017]
]
I need to make a fix year array like:
newYearArr = [ 2019, 2018, 2017 ]
The value at index 0 is the highest value at index 0 of any of the arrays, the value at index 1 is the highest at index 1, etc.
This is what I have done:
var highestValue = []
for(var i = 0; i < yearArr[0].length; i++){
highestValue.splice(i,0,0)
for(var j = 0; j < yearArr.length; j++){
if(yearArr[i][j] > highestValue[i]){
highestValue[i] = yearArr[i][j]
}
}
}
but it always returns
newYearArr = [2019, 2019, 2019]
[ [1, 2, 3], [1], [1, 2, 3, 4, 5, 6] ]. In fact, there could even be non-arrays in there. I mention it because it helps to know this when trying to work with them.