1 回答
TA贡献1854条经验 获得超8个赞
var jsons = [
{"id":"123456","info":"这是普通用户"},
{"id":"876543","info":"这是尊享用户"},
{"id":"87654321","info":"这是高级用户"},
{"id":"87654311","info":"这是尊享用户"},
]
function f(jsons,num) {
var num8 = num.substr(0,8);
var num6 = num.substr(0,6);
var result6 = '';
var result8 = '';
for(var i = 0,len = jsons.length; i < len;i++) {
var id = jsons[i].id;
if(id == num8) {
result8 = jsons[i];
break;
}
if(id == num6) {
result6 = jsons[i];
}
}
return result8 ? result8 : result6;
}
添加回答
举报