📜  [symbol.iterator] - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:19.238000             🧑  作者: Mango

代码示例1
const iterable1 = {};

iterable1[Symbol.iterator] = function* () {
  yield 1;
  yield 2;
  yield 3;
};

console.log([...iterable1]);
// expected output: Array [1, 2, 3]