javascript数组示例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript数组示例相关的知识,希望对你有一定的参考价值。
javascript arrays up and down
//--------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数组示例的主要内容,如果未能解决你的问题,请参考以下文章
html PHP代码片段: - AJAX基本示例:此代码演示了使用PHP和JavaScript实现的基本AJAX功能。