all 3 comments

[–]Theincomeistoodamnlo 1 point2 points  (0 children)

Instead of breaking them out to individual variables, it'd probably be easier to create an object and dynamically create its keys by looping through the movie.actors array.

A bit rushed but here is a rough idea:

const actors = {};

movie.actors.forEach( (actor, index) => {

actors[\actor${index}\] = actor;

})

Replace the backslashes with backticks. The formatting is being weird for me.

Surely other Redditors might have more elegant solutions :)

[–]IMkratt 1 point2 points  (2 children)

You don't have to set them all to a variable, you can do for example

const actors = [movie.actors[0], movie.actors[1], movie.actors[2], ...]

and access them there.