vuejs check word is availble in the string or not

Checking if a Word is Available in a String in Vue.js

To check if a word is available in a string in Vue.js, you can use the following approach:

  1. Using JavaScript String Includes Method: You can use the JavaScript String includes method to check if a word is available in a string. Here's an example of how you can achieve this in Vue.js:
// Example Vue.js method to check if a word is available in a string
checkWordAvailability() {
  let str = "Your string here"; // Replace with your actual string
  let wordToCheck = "word"; // Replace with the word you want to check
  if (str.includes(wordToCheck)) {
    // Word is available in the string
    console.log("Word is available in the string");
  } else {
    // Word is not available in the string
    console.log("Word is not available in the string");
  }
}
  1. Explanation: The includes method returns true if the string contains the specified word, and false otherwise. It is case-sensitive, so make sure to handle case sensitivity based on your requirements.

  2. Example Usage: For example, if you want to check if the word "hello" is available in the string "Hello, how are you?", you can use the includes method as follows:

let str = "Hello, how are you?";
let wordToCheck = "hello";
if (str.includes(wordToCheck.toLowerCase())) {
  console.log("Word is available in the string");
} else {
  console.log("Word is not available in the string");
}

This approach allows you to easily check if a specific word is available in a string in Vue.js.