結論
substr
とindexOf
を組み合わせれば良い
改行前の文字列を抽出する
// 改行前の文字が欲しい
const text = "test1\ntest2";
const text_first_line = text.substr(0, text.indexOf(`\n`));
console.log(`text_first_line=${text_first_line}`);
// 結果
test1
改行後の文字列を抽出する
// 改行後の文字が欲しい
const text = "test1\ntest2";
const text_second_line = text.substr(text.indexOf(`\n`) + 1);
console.log(`text_second_line=${text_second_line}`);
// 結果
test2
参考