Create new multidimensional Associative array from 2 arrays

前端 未结 3 1727
陌清茗
陌清茗 2021-01-15 12:15

I am looking for a solution to create a single multidimensional associate array in javascript.

What I have: I have a mysql database I am accessing with php and have

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-15 12:55

    What I need: A method to change the javascript array to a multidimensional array, pulling in the old value and adding it to the new array tied to the original key.

    Use aliases for the numeric indices to do this:

    var foo = ["Joe","Blow"];
    var bar = ["joe","blow"];
    var names = {};
    
    foo.fname = foo[0];
    bar.fname = bar[0];
    foo.lname = foo[1];
    bar.lname = bar[1];
    
    names.fname = [foo.fname,bar.fname];
    names.lname = [foo.lname,bar.lname];
    

提交回复
热议问题