I have a function where I get the first non empty value in a multidimensionnal array. In my example the first non empty value is B because I through the array by thecolumns first. Now, in this function, I need to get also the last non empty value. In my example "C" is the last non empty value. Because "C" is in the furthest column. So... How I can get C in my function ?
Thank you !
function findFirstAndLastValue (timeline) {
for (var col = 0; col < timeline[0].length; col++) {
for (var row = 0; row < 4; row++) {
if (timeline[row][col] != '') {
return [row, col];
}
}
}
}
function getFirstAndLastValue() {
var projectTl = [
['','','A','A','',''],
['','B','B','','',''],
['','','','','C',''],
['','','D','D','','']
]
var position = findFirstAndLastValue(projectTl);
console.log(position)
}
getFirstAndLastValue();