JavaScript javascript数组示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript javascript数组示例相关的知识,希望对你有一定的参考价值。

//--------removing item from array
existingArray.splice( znum, 1);       //znum is the spot to remove 0-(length-1)
                                      //1 could be more if you want to remove more

//--------sort array by keys
//xOrderList[0] = { "name" : "Fred" , "ranktype" : "45" };
//xOrderList[1] = { "name" : "Jed" , "ranktype" : "35" };
//xOrderList[2] = { "name" : "Red" , "ranktype" : "55" };
xOrderList.sort(function(a,b) { return parseFloat(b.ranktype) - parseFloat(a.ranktype) } );  //highest to lowest
xOrderList.sort(function(a,b) { return parseFloat(a.ranktype) - parseFloat(b.ranktype) } );   //lowest to hights by ranktype

//--------duplicate an array
var xNewArray = existingArray.slice();
//note that if the array contains arrays or objects, this will not work as they are just pointers to those items

//--------duplicate an array of arrays
	function duplicateArray( xArray ) {
		var xTempArray = [];
		console.debug( xArray.length );
		for (var x=0; x<xArray.length; x++){
			xTempArray.push( xArray[x].slice() );
		}
		return xTempArray;
	}
var xNewArray = duplicateArray( existingArray );

以上是关于JavaScript javascript数组示例的主要内容,如果未能解决你的问题,请参考以下文章

javascript里面的数组,json对象,动态添加,修改,删除示例

javascript JS:数组映射方法示例

javascript JS:数组过滤方法示例

javascript数组示例

JavaScript数组示例

javascript LoanerUtils使用数组的类和方法示例