Inconsistent behavior with Map.entries

75 views Asked by At

When I run the following code in dev console, I get the expected response:

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}`);
}

returns:

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

However, when I run the exact same code in a different browser environment, specifically inside a Cordova app, I'm getting the response:

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

The following code without the .entries() still works in that environment.

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

I am still able to successfully call map.entries(), which returns the correct response of MapIterator {1 => 'one', 2 => 'two', 3 => 'three'}. It is when it's in the for ... of statement that is the issue.

Cordova Android userAgent: 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' Working browser userAgent '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

Cordova iOS user agent Mozilla/5.0 (iPhone; CPU iPhone OS 17_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148

Is there a possibility that the the for...of function does not support MapIterator in certain cases?

For more context: This issue seems to be specific to Cordova and there is already a github issue linked.

0

There are 0 answers