1. indexOf();
lastIndexOf();
例如:
2. 找元素位置函数findAll();
var arr = [6,4,6,33,576,0.145,36,66,814,‘apple‘,‘person‘,12];function findAll(a,x) {
var results = [],
len = a.length,
pos = 0;
while(pos < len) {
pos = a.indexOf(x,pos);
if(pos === -1) break;
results.push(pos);
pos = pos + 1;
}
return results;
};findAll(arr,‘apple‘);//[9]
3. 判断是否是数组
Array.isArray();
也可以:Object.prototype.toString.call(arr);
4.
时间: 2024-11-12 16:42:40