You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Map.entries()在Cordova环境中与for...of迭代的不一致行为问题

MapIterator在Cordova环境中无法被for...of遍历的问题

问题现象

在标准浏览器开发者控制台运行以下代码可得到预期输出:

const map = new Map();
map.set(1, "one");
map.set(2, "two");
map.set(3, "three");

for (const [key, value] of map.entries()) {
    console.log(`The value for key ${key} is ${value}`);
}

输出结果:

The value for key 1 is one
The value for key 2 is two
The value for key 3 is three

但在Cordova应用环境中运行相同代码时,会抛出错误:

Uncaught TypeError: map.entries is not a function or its return value is not iterable

关键细节:

  • 去掉.entries()后,代码可在该环境正常运行:
    for (const [key, value] of map) {
        console.log(`The value for key ${key} is ${value}`);
    }
    
  • 直接调用map.entries()能正常返回正确的MapIterator对象{1 => 'one', 2 => 'two', 3 => 'three'},仅在for...of语句中出现兼容问题。

环境用户代理信息

  • Cordova Android:Mozilla/5.0 (Linux; Android 13; sdk_gphone64_arm64 Build/TE1A.220922.033; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/103.0.5060.71 Mobile Safari/537.36
  • Cordova iOS:Mozilla/5.0 (iPhone; CPU iPhone OS 17_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148
  • 正常桌面浏览器:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36

问题核心

存在for...of在特定场景下不支持MapIterator的情况,该问题为Cordova环境特有,已有相关GitHub issue记录了类似的兼容问题。


内容的提问来源于stack exchange,提问作者funkypops

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 14:45:30