How to extract value from an array of array

前端 未结 6 1105
旧巷少年郎
旧巷少年郎 2021-01-29 03:32

I have an array of array stored. I need to extract the particular value from this arrays.

e.g allarray contain the list of arrays allarray= [Array[3],Array[3],Array[3]]

6条回答
  •  情书的邮戳
    2021-01-29 03:38

    If I understand you correctly, your array looks like this

    var allarray = [["a1","b1","c1"],["a2","b2","c2"],["a3","b3","c3"]];
    

    To get c1, c2, and c3 you could just do this

     var c1 = allarray[0][2], c2 = allarray[1][2], c3 = allarray[2][2];
    

    or you could do a loop to put all of the cs in a single array of its own

    var cs = [];
    for(var i = 0; i < allarray.length; i++) {
      cs.push(allarray[i][2]);
    }
    

提交回复
热议问题