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

How can I wrap each multidimensional array into html element?

I have array

0: ['a', 'n', 'i', 'm', 'a', 'l'] 
1: ['c', 'a', 'r'] 
2: ['f', 'l', 'o', 'w', 'e', 'r']

I want to wrap each array into html element. for example

<div><span>c</span><span>a</span><span>r</span></div>

<div><span>a</span><span>n</span><span>i</span><span>m</span><span>a</span><span>l</span></div>

How can I achieve this using jQuery?

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

>Solution :

const input = [
  ['a', 'n', 'i', 'm', 'a', 'l'],
  ['c', 'a', 'r'],
  ['f', 'l', 'o', 'w', 'e', 'r']
];

for (let i in input) {
  console.log('<div><span>' + input[i].join('</span><span>') + '</span></div>');
}
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