The following code should remove any \n and replace them with an empty space and then split the string into an array:
let
array = code.value.replace("\n", " ").split(" ");
code is a html textarea element:
JS:
const
code = document.querySelector("#code");
HTML:
<textarea id="code" cols="60" rows="30">text = simple\ntext = line\ntext = program</textarea>
code.value is set to:
'text = simple\ntext = line\ntext = program
'
The following is what it returns:
['text', '=', 'simple', 'text', '=', 'line\ntext', '=', 'program']
What it should return:
['text', '=', 'simple', 'text', '=', 'line', 'text', '=', 'program']
Please help - I'm starting to go insane because of this stupid little bug.
0 comments