We have a sentence as a string and an array of some of the phrases in the string like this:
const sentence = "I told her your majesty they are ready";
const phrases= ["your", "they are ready"];
I want to split the sentence
string into array of arrays in which each array has been spliced based on phrases
.
The desired result would be this:
[ ["I told her"], ["your"], ["majesty"], ["they are ready"] ]
We split the 'I told her' into one array because we want to have 'your' in an individual and separate array (because 'your' is one of the phrases elements).
I used a for loop to substring the sentence by iterating through the phrases with no luck.