let li: Element[] = document.getElementsByTagName('span');
I get the type conversion error, how to store the values in 'Element[ ]' ??
let li: Element[] = document.getElementsByTagName('span');
I get the type conversion error, how to store the values in 'Element[ ]' ??
The object returned from
document.getElementsByTagName('span')
is not compatible with an array object. You need to declare it as following:If you really need this to be an array object you can use:
Try creating the implicit form of the variable first, then transfer this definition explicitly:
To..
Then..
The problem here is that
getElementsByTagName
returns an array-like object, not an actual array. You need to coerce it to one first using the spread operator (or[].slice.call(...)
for ES5):