2024-05-16 00:32:15
数组遍历很简单啊,不过楼主应该是想命名后遍历吧
var data = [
[3, "1", "888888@qq.com", "Mac", 1, 25, 1231231233, "1"], [2, "1", "896886824@qq.com", "Mac", 1, 25, 1231231222, "1"]
], i = 0, line, o = {}, keys = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; //这儿写应该有的名字,这里是示范
while (function (a, b, c, d) {
if (c = c && c[d] || 0, a = "object" == typeof a && a ? a : {}, "object" == typeof c)
for (var e in b)
a[b[e]] = c[e] || null;
return a
}
(o, keys, data, i++)) {
//这儿o就自动处理为{'a':3,'b':'1'....}的对象了
}
我就是想直接获取到值,不用命名后遍历可以吗?
当然可以了,
var data = [
[3, "1", "888888@qq.com", "Mac", 1, 25, 1231231233, "1"], [2, "1", "896886824@qq.com", "Mac", 1, 25, 1231231222, "1"]
], i = 0, line;
for(;i<data.length;i++){
line = data[i];
//line[0],line[1],...,line[7]
}
//上面这种就是有时候容易弄乱了
//前面的遍历弄复杂了,因为急着要去洗澡,其实可以这样简单的遍历
while (function (id, name, email, system, sex, age, time, alived) { //
if (arguments.length) {
//在这儿遍历
return true;
}
}
.apply(null, data[i++] || []));
//这个方法可以记住格式就行了,遍历二维数组,重命名变量,一锅端
while(function(arg1,arg2,...argN)){if(arguments.length){
//这样写,更好看点吧。
return true;}}.apply(null, {your_data_array}[i++]||[]));
2024-05-16 04:00:13
2024-05-16 02:06:19