How to make an array from a string by newline in JavaScript? May 31, 2023 by Tarik Use split() Fore example str = "abc\ndef"; console.log(str.split("\n")); will print out ["abc", "def"]