JavaScript's split() method automatically adds the \r character at the end of the string
P粉738248522
P粉738248522 2023-09-03 12:15:15
0
1
647
<p>I'm trying to create an array with the fetched data and create a new collection with it, but the resulting string has \r at the end: </p> <pre class="brush:php;toolbar:false;">export const WordSetFn = async () =>{ let wordSet; await fetch(wordsSet).then((resp) => resp.text() ).then((resp) =>{ const wordSetArray = resp.split("\n") wordSet = new Set(wordSetArray) }) return {wordSet}; } // word set would look like this: {"above\r",...}</pre> <p>And the txt file I'm getting the data from is a bunch of words, each word is on the next line, like this: </p> <pre class="brush:php;toolbar:false;">aback abase abate abbey abbot Abhor Abide abled Abode abort ...</pre> <p>Now why is \r added after every word? What does \r mean? </p>
P粉738248522
P粉738248522

reply all(1)
P粉066725148

\r is a carriage return character, \n is a line feed character, \r\n is a carriage return character plus a line feed character.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template