Slice X Amount from an Array

Javascript Add comments

Send back chuncks from an array


var catImgs = ["1", "2", "3", "4", "", "6", "7", "8"];

var arr = newArray(catImgs,4);

function newArray(arr, count){
            var temp = [];
            var temp2 = [];
            var current = 0;
            for(var i = 0; i < arr.length; i++){
	      var obj = new Object
	      obj.id = i;
	      temp.push(obj);
	            
            }
            for(var j = 0; j < Math.ceil(temp.length / count); j++){
                temp2.push(temp.slice(current, current + count))
                current += count;
            }
            return temp2;
        }

Leave a Reply

visit my other website here >> noeone
Entries RSS Comments RSS Log in