[BUG feedback][3.8.6] The result of loop traversal after compilation is wrong

Reproduce code

import { _decorator, Component, Node } from "cc";
const { ccclass, property } = _decorator;

@ccclass("MainScene")
export class MainScene extends Component {
  protected onLoad(): void {
    const map = new Map([
      ["key1", "value1"],
      ["key2", "value2"],
    ]);
    const values = [...map.values()];
    for (const v of values) {
      console.log(v);
    }
  }
}

The above code can output the results normally in the preview environment:

234324324

But after choosing web-desktop build, the output becomes:

1 Like

Problem analysis given by AI

Cause Analysis:

  1. map.values() returns MapIterator<string>
  2. The spread operator may be converted to a method ... in some compilation environments. concat()
  3. [].concat(iterator) The iterator object itself is used as the element, not the value it contains.
  4. So the final array contains only one element: MapIterator the object