Consider the following scenario in JavaScript:
data = [[5,3,2],[2,7,4],[4,6,3],[2,6,4]]
An idea is to create a function that can take an array and an index as inputs, and then return a new array consisting of only the values at that specific index from each sub-array.
For instance:
result = customFunction(data, 1);
//expected outcome: result = [3,7,6,6]
Is there an efficient and effective way to achieve this objective?