为什么我得到这个错误 (new Set(...)).slice is not a function?
Why I get this error (new Set(...)).slice is not a function?
我尝试在任何在线代码编辑器中运行此代码,但我总是出错
(new Set(...)).slice is not a function
代码:
myarray = ['d','s', 'a'];
chr_arr = [...new Set(myarray)];
为什么我会收到这个错误?
这仅在 ECMAScript 6 上有效
您需要在 tsconfig.json 中进行配置,但在线代码编辑器 (stackblitz) 无法编辑
您无法编辑 stackblitz,因为很遗憾 tsconfig.json 不可用。
但现在你可以使用 Array.from
myarray = ['d','s', 'a'];
chr_arr = Array.from(new Set(myarray));
更多信息https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
我尝试在任何在线代码编辑器中运行此代码,但我总是出错
(new Set(...)).slice is not a function
代码:
myarray = ['d','s', 'a'];
chr_arr = [...new Set(myarray)];
为什么我会收到这个错误?
这仅在 ECMAScript 6 上有效
您需要在 tsconfig.json 中进行配置,但在线代码编辑器 (stackblitz) 无法编辑
您无法编辑 stackblitz,因为很遗憾 tsconfig.json 不可用。
但现在你可以使用 Array.from
myarray = ['d','s', 'a'];
chr_arr = Array.from(new Set(myarray));
更多信息https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from