How to skip and execute functions in javascript for a Json array

I want to do this in javascript:

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

I have a json array. I want to get two blocks of records from this json array, as above linq code in javascript. Is it possible and how?

+4
source share
1 answer

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

Here is 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) 
+4
source

Source: https://habr.com/ru/post/1481514/