The error “SyntaxError: Unexpected token ‘:'” is indicating that the JavaScript interpreter is encountering a colon (‘:’) in a place where it is not expected.
In this case, it appears that the issue is with the syntax of the variable declaration. In JavaScript, when you want to declare an array with a specific type of elements, you can use the type followed by []
instead of :[]
.
Here is an example of the correct syntax for declaring an array of numbers in JavaScript:
let numInArray: number[] = [];
or
let numInArray = [] // This will be considered as Array<any>
You can also use the Array<Type> to define the type of element which array will contain.
let numInArray: Array<number> = [];
It should fix the issue and your code should work without any error.