0
let arr=["a","b","c"]
for (let i=0;i<3;i++){
let arr[i]=i
}

//Result is expected to be be let a=1 ; let b=1; let c=1;

//Why isnt this working and how do we initialise multiple variables using for loop to get a=1;b=1;c=1 ?

Your help will be appreciated

  • Get rid of the `let` inside the loop; it's a syntax error. The array is already declared. – Pointy Sep 22 '20 at 12:20
  • I realized the first part of the question, "Why isn't this working?", is not answered in the dupe. But the answer is simply, because it's invalid syntax according to the language specification. – Heretic Monkey Sep 22 '20 at 12:25
  • I don't think it's not a duplicate of the flagged question. But it is a duplicate of this: https://stackoverflow.com/questions/5117127/use-dynamic-variable-names-in-javascript – Lionel Rowe Sep 22 '20 at 12:26
  • https://stackoverflow.com/a/42739390/10079978 check this hope this will work for u – Muhammad Fazeel Sep 22 '20 at 12:33

0 Answers0