Skip to content
Advertisement

Filter an Array of strings using Filtered String and Remove from Original Array

I want to remove some elements from the array containing the word Evil (filterString).

JavaScript

Here is what I get for the original array (guests):

    ['Partner', 'Nice Relative 2', 'another evil', 'another one', 'strange Evil is here', 'someone Nicer']

Just want the guests array updated once the desired string (Evil) is filtered.

Advertisement

Answer

Since you want to mutate the original array then you can do as:

JavaScript

1) You can easily achieve the result using filter and match as:

JavaScript

2) You can also do this using forEach and match as:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement