WebMasterCampus
WEB DEVELOPER Resources

Javascript Check Substring Present Inside String

Learn how Javascript can Check Substring Present Inside String


Javascript Check Substring Inside String

If we need to check a substring is present inside a string we can easily check using indexOf() function. You can initiate IndexOf call with a string.indexOf(substring). The following example check “an” is present in country name “Japan”.

Examples


message = "This email is confidential"
message.indexOf("confidential")

country = "Japan"
country.indexOf ("an")

countries = ["China", "USA", "Finland", "Germany"]

countries.map(function(item){
  return item.indexOf("an")
})

Learn More about Javascript indexOf()

Learn More about Javascript map()

Created with love and passion.