3

I tried to run this code in any of the online code editors but I always get error

(new Set(...)).slice is not a function

Code:

myarray = ['d','s', 'a'];
chr_arr = [...new Set(myarray)];

why I get this error ?

zac
  • 4,495
  • 15
  • 62
  • 127

2 Answers2

4

you can't edit stackbiltz beacuse tsconfig.json is not available unfortunately . but for now you can use Array.from

myarray = ['d','s', 'a'];
chr_arr = Array.from(new Set(myarray));

More info https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from

Amr.Ayoub
  • 718
  • 9
  • 20
1

This only valid on ECMA Script 6

You need configure in tsconfig.json but online code editor (stackbliz) can't edit

https://angular.io/guide/typescript-configuration

Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62