Reputation: 65
const EleList = [1,2,3]
name = 'Ele'
const render = function(type){
window[type + 'List'].forEach(function(value){
console.log("LOL")
render('Ele')
What am i supposed to replace the window[name + 'List'] with to call an array using strings.
Upvotes: 0
Views: 1257
Reputation: 28177
const
or let
variables are not added to the global window
object.
Replacing const
with var
should solve your problem.
var EleList = [1,2,3]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
Global constants do not become properties of the window object, unlike var variables.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let
Just like const the let does not create properties of the window object when declared globally (in the top-most scope).
Upvotes: 1