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 to add 2 strings to an array one down the other

I have two strings i need to add those to the array and display one down the other

const str1 = "SamsungGalaxy A52"
const str2 = "SamsungGalaxy A53"

let arr=[]

arr.push(str1,str2)

and I want to display like

  SamsungGalaxy A52
  SamsungGalaxy A53

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 :

You can try something like it:

const product_1 = "SamsungGalaxy A52";
const product_2 = "SamsungGalaxy A53";

let products = [];

products.push(product_1, product_2);

const ul = document.querySelector('ul');

for (const product of products) {
  const li = document.createElement('li');
  li.textContent = product;
  ul.append(li);
}
li {
  list-style: none;
}
<ul>
</ul>
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