Currently, I'm in the process of developing a JavaScript function that accepts an array as an argument and returns the first item in the array. The function should be able to handle arrays of any size. While my current implementation seems to be effective in the console, my instructor believes there may be a more efficient approach:
var array = [];
function getFirstItem(array) {
for (var i = 0; i < array.length; i++) {
console.log(array[0])
};
}
Any suggestions or guidance on optimizing this function would be greatly appreciated. I've delved into data structures and arrays, but I'm struggling to simplify or improve my current solution.