callback function in factory function [duplicate]

I’m trying to write a code that iterates through an array. If a callback function is passed as an argument the item should be passed as an argument to the callback function. If no callback function is called, the function should return items in an array.

const myFunction = (callback) => {
    let array = [1,2,3,4];
    let result = [];
    for(let i in array){
        callback ? callback(i) : result.unshift(array[i]);
    }
    return {result, callback}
}

const print = (val) => {
    console.log(val)
}

myFunction(print())

but what I get in the console is this: undefined.
So, my question is, why is callback undefined? and how can I solve this problem?