陣列常用處理方法

2021-10-09 04:06:05 字數 857 閱讀 6584

一、遍歷陣列

二、排序

普通陣列sort,預設公升序

var  arr = [2,4,3,4,5];

console.log(arr.sort())//[2,3,4,4,5]

如果使用函式a-b是公升序,b-a是倒序

arr.sort(function(a,b))

console.log(arr)//[5, 4, 4, 3, 2]

物件陣列按照某個屬性值排序 :同理也可以按照sort的函式來進行延伸

比如按照adrcount值來排序

var arr1 =[,,]

arr1.sort(function (a, b) );

console.log(arr1)

// [

// // ]

當然也可以更為通用,比如想按照哪個屬性排序就按照哪個屬性來排序:value1 - value2為公升序;value2 - value1為降序;

function compare(property) 

}arr1.sort(compare('adrpro'));

console.log(arr1)

// [,

// ,

// ]

常用處理字元(陣列)方法

一.c種常用處理字元 陣列 方法 1.在c中,char s 1000 定義乙個字元陣列 s,注意字串結束標誌 0 可以單獨對其中乙個字元操作 scanf c s i printf c s i 對整個字串操作 scanf s s printf s s scanf s s s str1,str2,str...

MySQL常用處理方法

1.replace into replace into t id,update time values 1,now 或 replace into t id,update time select 1,now replace into 跟 insert 功能類似,不同點在於 replace into 首...

PHP常用處理陣列函式

依次拼接陣列 array1 array 1,2,3,4,5 array2 array 6,7,8,9,10 array3 array merge array1,array2 拼接 print r array3 執行結果 array 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 ...