Function index?

Thank you. English is not my first language so sometimes I have a lot of misunderstanding. Seems I have a lot to learn both in English and in coding…

Hi,
I tried to break this down into steps so everything wasn’t all done in one line. Also, see comments that pertain to the first pass of the first call to the function.

Those intermediate results could also be logged out to console if that helps some.

Hope this helps some.

@alhazen1
Hi, I think that is helpful, could you please check if my code works too? I think it’s kind of the same idea.

    let obj = {};
    
    for(let i = 0; i < arr.length; i++){
        obj[arr[i][str]] = arr[i];
    }
    
    
    return obj;
};

Assuming that str is the second parameter passed to index(arr,str) then yes, it will work fine.

I broke the example up into steps to show where these values came from but if you look at the last commented out line in the for…loop it is exactly the same thing with different variable names.