Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

set array items into separate variables

I am trying to set each item in an array into their own variables. Here is what the array looks like:

labels = ["label1", "label2", "label3", "label4", "label5"]

I have already created the variables:

let name1;
let name2;
let name3;
let name4;
let name5;

So I want to set each array item to each variable so that they look like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

let name1 = "label1";
let name2 = "label2";
let name3 = "label3";
let name4 = "label4";
let name5 = "label5";

I am not really sure with how to proceed with this.

>Solution :

Is this what you want?

           const labels = ["label1", "label2", "label3", "label4", "label5"]

           var name1 = labels[0];
           var name2 = labels[1];
           var name3 = labels[2];
           var name4 = labels[3];
           var name5 = labels[4];

           console.log('name1=' + name1);
           console.log('name5=' + name5);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading