I have a series of varying strings which I need to turn into arrays on every second occurrence of \n
, for simplicity please consider the next example:
const str = 'banana\napple\nmango\n3.5'
//I have tried and failed with:
const arr = str.split(/(^\n)+\n(^\n)+/)
// Result should be:
// const arr = ['banana\napple', 'mango\n3.5']
Do I have to use a loop here or what?