Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list array inside a javascript alert

Tags:

javascript

I have an array of strings, I want to display the content with some html tags in the alert level. I tried this:

array = ["toto", "titi"]
alert("*" + array.join('\n'))

but the problem here, I got only the first line with *. how can I resolvr this probleme to show all the lements with * in the begining ?

like image 959
Java user Avatar asked Dec 01 '25 06:12

Java user


1 Answers

Array.map()

You should use map method to create a new array populated with each element having * prefix.

const array = ["foo", "bar"];

alert(array.map(value => `*${value}`).join('\n'));
like image 163
Vinay Sharma Avatar answered Dec 03 '25 18:12

Vinay Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!