0

JavaScript 还是新手,我正在我的 JSON 中搜索数字,但 JSON 有很多空值。如何忽略搜索中的空值?

$.each(geojson.features, function (i, v) {
    if (v.properties.code.toString().search((/2/i)) != -1) {
        Count++;
    }
});

我在这里先向您的帮助表示感谢。

4

1 回答 1

1

你可以这样做

 if (v.properties.code && v.properties.code.toString().search((/2/i)) != -1) {
            Count++;
        }

先检查值不为空,然后搜索字符串

于 2012-12-29T12:12:57.847 回答