How can I create a two dimensional array in JavaScript?

后端 未结 30 4355
天涯浪人
天涯浪人 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条回答
  •  别那么骄傲
    2020-11-21 05:29

    var playList = [
      ['I Did It My Way', 'Frank Sinatra'],
      ['Respect', 'Aretha Franklin'],
      ['Imagine', 'John Lennon'],
      ['Born to Run', 'Bruce Springsteen'],
      ['Louie Louie', 'The Kingsmen'],
      ['Maybellene', 'Chuck Berry']
    ];
    
    function print(message) {
      document.write(message);
    }
    
    function printSongs( songs ) {
      var listHTML;
      listHTML = '
      '; for ( var i = 0; i < songs.length; i += 1) { listHTML += '
    1. ' + songs[i][0] + ' by ' + songs[i][1] + '
    2. '; } listHTML += '
    '; print(listHTML); } printSongs(playList);

提交回复
热议问题