How to make an array from a string by newline in JavaScript?

前端 未结 2 1937
执念已碎
执念已碎 2020-12-30 19:38

I\'ve got this:

var quoted_text = window.getSelection;

For example:

Accepting the Terms of Service

The Stack Exchange Netw

相关标签:
2条回答
  • 2020-12-30 20:37

    Use javascript .split() function to create an array with elements splitted by '\n' and then manually iterate through that array and add '<' for each item. The following code may help :

    var str="How\nare\nyou\ndoing\ntoday?";
    var n = str.split("\n");
    for(var x in n){   
        n[x]= '>'+n[x]; 
        alert(n[x]);
    }
    
    0 讨论(0)
  • 2020-12-30 20:39

    Use split()

    Fore example

    str = "abc\ndef";
    console.log(str.split("\n"));
    

    will print out

    ["abc", "def"] 
    
    0 讨论(0)
提交回复
热议问题