FANDOM


Programmer's Wiki
This page has been moved to the Programmer's Wiki.
Please do not make any changes or additions to this page.

Any modifications, if still appropriate, should be made on Array merge at the Programmer's Wiki.

function array_merge(arr) {
	var merged = arr;
	for (var i = 1; i < arguments.length; i++) {
		merged = merged.concat(arguments[i]);
	}
	return merged;
}

In some situations is better use:

function array_merge() 
{
	var merged = new Array();
	for( var i = 0; i < arguments.length; i++ )
	{
		for( var j = 0; j < arguments[i].length; j++ )
		{
			merged = merged.concat( arguments[i][j] );
		}
	}
	return merged;
}


Example Javascript UsageEdit

arr1 = new Array("dog", "cat", "mouse");
arr2 = new Array("lion", "tiger", "bear");
arr3 = new Array("rabbit", "buck", "snake");
arr4 = array_merge(arr1, arr2, arr3);
alert(arr4); /* Gives:  dog,cat,mouse,lion,tiger,bear,rabbit,buck,snake  */

The usage is same for both functions.