I have a code block which is creating an array where I am searching for certain text using regex and if its found, I am removing that element and inserting two new elements in its place with below code:
var Unique_items = ["P name1-Test based fee-200 Samples", "P name2-night fee-GG", "P name2-day light test-HH" ];
for (var i in Unique_items){
var temp_index = [];
var check_test_based_fee = new RegExp(/Test based fee/).test(Unique_items[i]);
if (check_test_based_fee==true){
temp_index.push(i);
temp_index.push(i+1);
Unique_items.splice(temp_index[0],"P name1-TBF-200 Samples:commitment");
Unique_items.splice(temp_index[1],"P name1-TBF-200 Samples:Excess");
}
}
Logger.log(Unique_items);
So, whenever Test based fee is encountered in any element, it should replace it in the array with two new elements as the Unique_items here to be
["P name1-TBF-200 Samples:commitment", "P name1-TBF-200 Samples:Excess","P name2-night fee-GG", "P name2-day light test-HH"]
I am not getting how to dynamically prepare and insert the
P name1-TBF-200 Samples:commitment", P name1-TBF-200 Samples:Excess
Please help!