Verify whether a specific word contained in a string matches any of the words in an array, and if there is a match, eliminate it from

Looking for some assistance here - I'm trying to perform a case insensitive check to see if a word in a string matches any words in an array. If there is a match, I then want to remove that particular word from the string. Can anyone suggest the best approach to achieve this?

Your help is greatly appreciated.

var testArray = new Array('that','from','again');
    
var testString = "It's That time again";

In the given example, the words 'That' and 'again' should be eliminated from the string.

Answer №1

To extract individual words from a string, you can split the string and then filter out certain words before rejoining them:

var excludedWords = new Array('that','from','again');
var inputString = "It's That time again";

var resultString = inputString.split(' ').filter(word => !excludedWords.includes(word.toLowerCase())).join(' ');
console.log(resultString);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React Redux is functioning flawlessly when paired with Sample A code, but unfortunately it is encountering a dispatch error when used with

Having an issue with React Redux: Sample A Code works perfectly, but encountering dispatch error with Sample B Code I am working on displaying Post records and then sending them back to the server backend via an onclick function. In order to achieve this ...

Dynamic autocomplete feature with AJAX integration for filtering in Flask

Looking for some guidance on creating an HTML form with two input fields. Check out the HTML template code below: <form role="form" action="/cities/" method="get" autocomplete="on"> <label for="#input1"><strong>Country:</strong&g ...

Setting up type definitions using gulp-typescript

I have a web development project that consists of various JavaScript files and one TypeScript file. I am utilizing the most recent version of TypeScript with its allowJs flag enabled. Despite wanting to compile my project using a gulp task, I keep encounte ...

The method of iterating over a string in key-value pairs

How can I efficiently loop through a string and extract key/value pairs? The data is provided to me as a single string using the jstorage plugin. I attempted to split the string into an array, but the resulting key/values were not as expected. For exampl ...

Determining the visible dimensions of an iframe

Is there a way to determine the visual size inside an iframe using JavaScript or jQuery? In this scenario, only a portion of the iframe is displayed. The iframe itself has dimensions of 300x300, but it is being limited by a div to 300x100. <div style= ...

execute javascript code after loading ajax content

Although this question may have been asked before, I am completely unfamiliar with the subject and unable to apply the existing answers. Despite following tutorials for every script on my page, I have encountered a problem. Specifically, I have a section w ...

Instructions for removing all entries from a DynamoDB table

I am facing a challenge with deleting multiple items from a DynamoDB table. While the documentation suggests dropping and recreating the whole table, I want to avoid this approach as my table was created using AWS Amplify and I don't want to risk disr ...

What is preventing my form from submitting on its own?

Is there something wrong with submit()? It doesn't seem to be working for me. <html> <head> <title>This is the title</title> <script type = "text/javascript"> function onLoad() { document.get ...

Ensure to verify if any array indexes are empty in VBA, including the possibility of containing objects

Is there a way to accurately check for empty indexes in a Variant array without triggering exceptions for regular data types? I currently use Is Nothing to identify empty indexes that contain objects, but it causes issues with non-object data types. Here i ...

What is the best way to incorporate multiple variables in a MySQL query when using Node.js?

I'm facing a challenge where I need to input student data into a table using the parent key as a foreign key. The parent information is included in the same JSON object, with an array of students inside it. My goal is to retrieve the parent Id from th ...

The Angular function fails to execute when clicked

I am trying to trigger a new page launch when a cube is clicked using Angular. Unfortunately, my current code doesn't seem to be working as expected and nothing happens when I click the cubes. This makes me wonder if there is something wrong with my i ...

How can I create a detailed highchart map of Korea that accurately includes Dokdo in its design?

I am currently working on a project to create a comprehensive map of Korea using highchart. One major challenge I have encountered is the absence of Dokdo on the standard map of Korea provided by highchart. Is there a way for me to develop a map that inc ...

Combining strings in a loop with Angular's $scope

I have four values with the following names : $scope.restaurant.restaurantIsTop $scope.restaurant.restaurantIsRecommended $scope.restaurant.restaurantIsNew $scope.restaurant.restaurantIsPromoted Each of these values can be either 0 or 1. My goal is to c ...

Transforming a jQuery menu into an active selection with Vue JS

I am looking to transition away from using jQuery and instead utilize Vue for the front end of a menu. Specifically, I need to add an active class and a 'menu-open' state to the appropriate nested list items, similar to what is achieved in the pr ...

Can someone assist me in determining the UV mapping process from Ricoh Theta S Dual Fish Eye to a Three.js r71 SphereGeometry?

Currently, I am attempting to replicate the three.js panorama dualfisheye example using Three.js version r71. It is crucial for me to adhere to r71 because I plan to integrate this code into the Autodesk Forge viewer, which relies on Three.js r71. I have ...

Locate elements across multiple HTML pages using querySelector!

I am facing an issue with my website structure. The main page (index.html) consists of a header, main section, and footer. The header includes a Hamburger icon that triggers a navbar with submenus and sub-sub menus generated through JS scripts fetching dat ...

Obtain Information from an Ajax GET Request

My question is fairly straightforward. I have this Ajax function: function fillProductLine(obj) { $.ajax({type: "POST", url: '/orderOnline/index.php/Orders/searchProductLine', async: false, data: { cd_cpl ...

Preventing flickering when updating UI elements with AngularJS

A website I created showcases a variety of progress bars, each representing the progress of various backend tasks. For example: <div ng-repeat="job in jobs"> <div id="progressbar">...</div> </div> I am using a $resource for the ...

Function for adding numbers in Javascript with currying

Can you help me solve this interesting problem? I need a javascript function that can return the sum of all arguments passed to it, even when called multiple times. I have identified different ways in which the function can be called - sum(1, 2, 3, 4); ...

Can anyone recommend any JavaScript or jQuery thumbnail scripts that are similar to TimThimb (PHP)?

TimThumb is a versatile tool that can quickly generate thumbnails from images of any size or dimensions to fit any desired size. It has the ability to resize, crop, or zoom crop images without any hassle. I've been on the lookout for JavaScript alter ...