My need is to remove an element from an array when an array element partially matches with some other element of a string, remove that element.
For example,
var res1 = [ " Proj -> Phase-1 -> Tower-1 -> Floor-2 ", " Proj -> Phase-2 ", " Proj -> Phase-2 -> Tower-1 " ]; i.e if my
res1[2]="Proj->Phase-2->Tower-1" and
res1[1]="Proj->Phase-2" res1[1] partially matches with res1[2]. So i need to remove res1[2]. After that i want the remaining array values. But its not working properly.
Here's what I've tried, but I'm not getting the result I expect:
for (i = 0; i < res1.length; i++) { for (j = 0; j < res1.length; j++) { if (res1[i] != res1[j]) { if (res1.indexOf(res1[j]) === 0) { console.log(res1); console.log(res1[j]); delete res1[i]; } } } } i.e if string1 "Proj->Phase-2" exactly in string2 "Proj->Phase-2->Tower-1" , then string2 need to be deleted. Even if a string3 "Proj->Phase-1->Tower-1" compared with string1, it is not exactly the same. So it should not be removed
proj, shouldn't that ensure that all other items be removed? Please share enough test data with intended output for each test case