Site logo

Array

Miscellaneous functions for arrays

While Loop with Array.pop() Gotcha

Extract all Parts (sub-arrays) of a given Array

ESTK Data Browser may Fail in Displaying Associative Arrays

Large arrays and performance issues

Array.prototype methods are 'not so fast', especially shift, unshift, splice, so it might useful to split the work in smaller chunks to deal with smaller arrays.

	function chunkArray(a,s) {  
	var chunks = [];  
	var n = a.length;  

	if ( a.length < s ) return [a];  

	while (n--) {  
		chunks[chunks.length] = a.splice(0, s);  
		n = a.length;  
	}  

	return chunks;  
}
   

On large arrays adding slice(0) ......everyItem().getElements().slice(0); can make a big difference.

See also snippets for array