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
CodePudding user response:
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>
CodePudding user response:
If you want to push two values to an array, you can do it with arr.push(str1, str2);
or arr.push(str1); arr.push(str2);
const str1 = "SamsungGalaxy A52"
const str2 = "SamsungGalaxy A53"
let arr=[]
arr.push(str1);
arr.push(str2);
// arr.push(str1, str2);
console.log(arr);