I have a string like this
let myarr = ['A511-0001-01', 'APWA-0001-03', 'APWA-9999-99'];
and i have a substring to filter myarr
like AP
.
let filteringCondition = 'AP';
how can i get myarr to (remove 'A511-0001-01'
) with Javascript?
Expected result:
myarr = ['APWA-0001-03', 'APWA-9999-99'];
Thanks for read. Im newbie
i don’t know to try with this specs
2
Answers
You can use the filter function like this
If this is a coding challenge and you need to have some king of universal way that can be applied in other languages, you can do something like this
But indexOf can be a method not present in all languages and you can write it easily using constructs available in all languages. It returns the first index of position where substring starts or -1 if examined string isn’t substring at all. You can rename it to be isSubstring and return true instead of index and false instead of -1.