Consider having the following string:
Apple Banana Pear
Pineapple Grapefruit Kiwi
Lime Lemon Cherry
If I am interested in extracting the line:
Pineapple Grapefruit Kiwi
how can I achieve this by identifying any index within the second line and locating the newline character before and after that index?
I attempted the following approach:
fruits[0].slice(fruits[0].indexOf("\n"),fruits[0]
.indexOf("\n", fruits[0].indexOf("\n") + 1))
However, this method does not take advantage of the index but merely extracts the entire second line. It resembles a brute force strategy to isolate the second line.