How to split string with newline (‘n’) in Node.js?

Sometimes, we want to split string with newline (‘n’) in Node.js.

In this article, we’ll look at how to split string with newline (‘n’) in Node.js.

How to split string with newline (‘n’) in Node.js?

To split string with newline (‘n’) in Node.js, we can use the string split method.

For instance, we write

const arr = "anbrnc".split(/r?n/);

to call "anbrnc".split with the regex /r?n/ to split the string by rn or n into separate strings.

Conclusion

To split string with newline (‘n’) in Node.js, we can use the string split method.