How to do skip and take functions in javascript for Json array

前端 未结 1 935
难免孤独
难免孤独 2021-01-13 15:41

I want to do that in javascript:

     for (int i = 0; i <= pieces; i++)
      {
       List piecesProuducts = productList.Skip(i * 2).Take(         


        
1条回答
  •  清酒与你
    2021-01-13 16:03

    A JSON array is just a JavaScript array, so you can use push and slice.

    Here's an example:

    var productList = [1,2,3,4,5,6,7,8,9,0]
    var piecesProuducts = []
    
    for (var i = 0; i <= 4; i++)
    {
        piecesProuducts.push(productList.slice(i*2, i*2+2));
    }
    
    console.log(piecesProuducts)
    

    0 讨论(0)
提交回复
热议问题