我想在 javascript 中访问数组中的元素,而无需执行 for 循环来访问它。
这是我的数组:
var array = [{
"title": "Warnings",
"numbers": 30,
"content": [{
"number": 3001,
"description": "There may be a problem with the device you are using if you use the default profile"
}]
}, {
"title": "Errors",
"numbers": 20,
"content": [{
"number": 1000,
"description": "No network is loaded"
}]
}]
我想在不执行 for 循环的情况下访问“警告”的“内容”属性。我目前正在做的访问它如下:
var content;
for(a in array) {
if(a.title == "Warnings") {
content = a.content;
break;
}
}
这在 javascript 中可行吗?