1. Home
  2. »
  3. Javascript
  4. »
  5. ECMAScript 6+ (ES6+) – Using Searching strings

ECMAScript 6+ (ES6+) – Using Searching strings

ECMAScript 6+ (ES6+) – Using Searching strings

ECMAScript 6, also known as ES6 or ES2015, brought many new features and improvements to JavaScript, making it more powerful and easier to use. One of the enhancements in ES6 is the ability to search for strings more efficiently using the new methods introduced.

One of the most commonly used methods for searching strings in ES6 is the includes() method. This method allows you to check if a string includes another string, returning true or false based on the presence of the specified string. Here’s an example:

function flashify_checkString(str, searchStr) {
    return str.includes(searchStr);
}

This flashify_checkString() function takes two parameters – str (the string to search in) and searchStr (the string to search for). It then uses the includes() method to check if searchStr is present in str and returns true if it is, and false if it isn’t.

Another useful method for searching strings in ES6 is the startsWith() method. This method allows you to check if a string starts with another specified string, returning true or false accordingly. Here’s an example:

function flashify_startsWith(str, searchStr) {
    return str.startsWith(searchStr);
}

In the flashify_startsWith() function, the startsWith() method is used to determine if str starts with searchStr. If it does, the function returns true; otherwise, it returns false.

ES6 also introduced the endsWith() method, which checks if a string ends with a specified string, returning true or false based on the result. Here’s an example of how you can use it:

function flashify_endsWith(str, searchStr) {
    return str.endsWith(searchStr);
}

The flashify_endsWith() function takes str as the string to check and searchStr as the string to look for at the end of str. It then uses the endsWith() method to return true if str ends with searchStr, and false if it doesn’t.

These ES6 string searching methods provide a more efficient and convenient way to search for specific strings within other strings, making JavaScript development easier and more streamlined.

Shashika De Silva

Shashika De Silva

Hey there! I’m a seasoned PHP developer with over 10 years of experience crafting awesome WordPress plugins and themes. I specialize in creating scalable and robust solutions for WordPress and WooCommerce, ensuring everything runs smoothly. Whether it’s cross-platform software development, web development, or diving into Sheets/Excel with Appscript, Macros, and VBA, I’ve got you covered. I’m all about delivering top-notch results that go beyond expectations. Let’s team up and turn your ideas into reality, making your project shine! Looking forward to working together and achieving something remarkable!

Select By Category

Flashify.Lab

Join our team
to create the best digital solutions.

Enhance your WordPress site’s functionality with custom plugins tailored to your unique needs. Our expert developers specialize in creating robust plugins that seamlessly integrate with WooCommerce, ensuring a streamlined user experience and enhanced site performance. Transform your ideas into reality with our bespoke plugin development services today

Scroll to Top