How can I create a two dimensional array in JavaScript?

后端 未结 30 4401
天涯浪人
天涯浪人 2020-11-21 05:25

I have been reading online and some places say it isn\'t possible, some say it is and then give an example and others refute the example, etc.

  1. How do I dec

30条回答
  •  猫巷女王i
    2020-11-21 05:47

    I had to make a flexible array function to add "records" to it as i needed and to be able to update them and do whatever calculations e needed before i sent it to a database for further processing. Here's the code, hope it helps :).

    function Add2List(clmn1, clmn2, clmn3) {
        aColumns.push(clmn1,clmn2,clmn3); // Creates array with "record"
        aLine.splice(aPos, 0,aColumns);  // Inserts new "record" at position aPos in main array
        aColumns = [];    // Resets temporary array
        aPos++ // Increments position not to overlap previous "records"
    }
    

    Feel free to optimize and / or point out any bugs :)

提交回复
热议问题