There is an array of 50 elements. This array is taken as an example, it may contain a different value. 73 elements, 92. 242. 841. The exact number of elements is not known.

There is a ListView; the size of the list is adjustable from the number of array elements. /ten. If the array is 50. Then in the ListView lists 50/10 = 5.

How to make every 10 items appear in the list?

Tobish obtained ListView of 10 elements. In the first element. mas [0] -mas [9] In the second 10-19. In the third 20-29, etc.


For Eugene.

There is a number of 100. It is necessary to go through all the numbers and pause for every ten.

  • see lodash, _.chank function - xFloooo
  • It is not entirely clear (it is not at all clear) what exactly you are going to achieve. Do you want to make a sheet with drop-down tabs or items on 10 elements in the item? - Eugene Troyanskii
  • @EugeneTroyanskii, Above updated for you - AndroLord
  • @xFloooo, thanks, but I need no third-party libraries. We need the algorithm itself using only the native - AndroLord
  • @AndroLord Do you need something like pagination (portion loading of elements)? - Eugene Troyanskii

1 answer 1

var arr = []; // Для примера 46 элементов в массиве for (var i=0;i<46;i++){ arr.push(i) } // разбиваем массив по 10 элементов var chanks = array_chunk(arr, 10); console.log(chanks) function array_chunk( input, size ) { for(var x, i = 0, c = -1, l = input.length, n = []; i < l; i++){ (x = i % size) ? n[c][x] = input[i] : n[++c] = [input[i]]; } return n; } 
  • It is a pity that Nitsche is not clear)). Especially the array_chunk function itself. (( - AndroLord