To map an array of stringified numbers to actual Numbers, I can simply pass the Number function:
let arr = ["0", "1", "-2.5"];
console.log(arr.map(Number));
Now I would like to use the same approach with document.getElementById
to map a list of id
strings to their corresponding DOM nodes:
let arr = ["a", "b"];
console.log(arr.map(document.getElementById));
<div id="a">a <span id="b">b</span></div>
which gives me
"TypeError: 'getElementById' called on an object that does not implement interface Document."
Can someone explain the error?