Destructuring issue

I tried to destructure the following array containing URLs with the array of small strings but it’s bringing up an error.

const verses = [
  "https://raw.githubusercontent.com/mdn/learning-area/main/javascript/apis/fetching-data/verse1.txt",
  "https://raw.githubusercontent.com/mdn/learning-area/main/javascript/apis/fetching-data/verse2.txt",
  "https://raw.githubusercontent.com/mdn/learning-area/main/javascript/apis/fetching-data/verse3.txt",
  "https://raw.githubusercontent.com/mdn/learning-area/main/javascript/apis/fetching-data/verse4.txt"
]

const ["verse 1", "verse 2", "verse 3", "verse 4"] = verses;

The error says “Uncaught SyntaxError: Invalid destructuring assignment target”. Can anyone tell me why that is? Is the syntax not correct or something?

NOTE: I’m a bit of a novice with JavaScript so forgive me if this might be an obvious problem to solve.

This is an array of strings instead of variables. You can’t assign anything to a string, only a variable.

@JeremyLT I actually tried this before and it didn’t work but then I remembered I accidentally left the spaces in so I had to type verse1 instead of verse 1. Thanks!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.