Javascript how to show each element of array on a new line

前端 未结 3 1568
小鲜肉
小鲜肉 2021-02-02 15:21

I have a string build form comma separated values I use split to get each value and after that I want to show each value on a new line but what really happens is th

3条回答
  •  情歌与酒
    2021-02-02 15:33

    i have modified your function bit cleaner.since already stefan mentioned your mistake.

    function splitDate(dates) {
            if (dates != null)
            {
                var dates = dates.split(',');
                var xxx = dates.length;
                console.log(xxx);
                for (var i=0; i

    the above function you can do it in a single line:

    if it's an array you can split into new line in following way:

    var arr = ['apple','banana','mango'];
    console.log(arr.join('\r\n'));
    

    if it's a string:

    var str = "apple,banana,mango";
    console.log(str.split(',').join("\r\n"));
    

提交回复
热议问题