Dynamically create a two dimensional Javascript Array

后端 未结 7 1789
臣服心动
臣服心动 2020-12-11 22:07

Can someone show me the javascript I need to use to dynamically create a two dimensional Javascript Array like below?

desired array contents:

7条回答
  •  轮回少年
    2020-12-11 22:29

    It sounds like you want to map the array of text for each $something element into an outer jagged array. If so then try the following

    var outterArray = [];
    $something.each(function () { 
      var innerArray = [];
      $(this).somethingElse.each(function () {
         innerArray.push($(this).text());
      });
      outterArray.push(innerArray);
    });
    
    alert(outterArray);
    

提交回复
热议问题