+ 1
Js: `${...arr}`
Where is the error in this quiz? var arr = [2,3,4]; var lit = `${...arr}`; console.log(lit[0];
6 Answers
+ 3
https://code.sololearn.com/Wma3zSx6o1i6/?ref=app
You just need to use the array destructuring syntax: var lit = [...arr];
+ 2
Ali Abdelhady
Thanks! With a minor modification of your example, it works:
var arr = [1, 2, 3, 4];
var lit = [...arr];
console.log(lit[0]);
+ 2
var arr = [2,3,4];
var lit = `${[...arr]}`;
console.log(lit[0]);
Use [] inside ${} so that lit variable makes a copy of arr variable
+ 1
Prof. Dr. ZoltĂĄn Vass well it does work as well, by using the same syntax inside the {}: `${[...arr]}`
https://code.sololearn.com/Wma3zSx6o1i6/?ref=app
0
Mirielle
The error is in this line:
var lit = `${...arr}`;
I still donât understand why. Perhaps destructuring canât be used in string literals?