我有一个具有重复键值对的对象。我需要遍历它并仅针对一个条件评估索引 [0] :
var cells = {"cells": [{"key": "-18", "key1": "-9", "key2": "-51", "key3": "23"}, {"key":
"-18", "key1": "-9", "key2": "-51", "key3": "23"}, {"key": "-18", "key1": "-9", "key2": "-51",
"key3": "23"}]};
到目前为止我的代码:
var result = true;
if (cells instanceof java.util.List && !cells.isEmpty()) {
for (var i = 0; i < cells.size(); i++) {
var cell = cells.get(i);
var key = cell.get("key");
var primeKey = key.get[0];
if (primeKey) {
if (parseInt(primeKey) < 5) {
result = false;
break;
}
} else {
result = false;
break;
}
}
} else {
result = false;
}
return result;
我得到的错误是:评估期间遇到的错误:TypeError: Cannot read property "0.0" from undefined (#12)