I'm struggling to find a solution to my current issue.
My goal is to retrieve the item at a specific index from a collection of separate arrays without merging them together.
Typically, to access the 3rd item in an array, you would use:
function getItemFromJustOneArray(index){
var my_array = [1,2,3,4,5,6];
return my_array[index];
}
getItemFromJustOneArray(2); // returns 3
However, my scenario involves multiple arrays that must remain separate and cannot be concatenated.
function getItemFromMultipleArrays(index){
var array1 = [1,2];
var array2 = [3,4,5];
var array3 = [6];
// I cannot use concat (or similar) to merge the arrays,
// they need to stay separate
// it could be any number of arrays, not just three
// return 3;
}
getItemFromMultipleArrays(2); // SHOULD RETURN 3
I've attempted various methods using loops, but haven't been able to find a viable solution.
If anyone knows of an elegant approach to this problem, I'd greatly appreciate your input.