Get the App
SLTechnology News&Howtos  ›  Development  › 

How JavaScript checks whether a string begins or ends with a specific sequence

Shulou Source: shulou.com Published: 2022-06-01 05:03:40 10月01日 Update

Xiaobian to share with you how JavaScript checks whether a string starts or ends with a specific sequence, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go and understand it together!

How to check if a string starts or ends with a specific sequence

To search at the beginning or end of a string, use the String.startsWith and String.endsWith methods.

const text = "Hello, world! My name is Kai! " console.log(text.startsWith("Hello")); // true console.log(text.endsWith("world")); // false The above is" How JavaScript checks if strings start or end with a specific sequence "All of this, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Characters strings openings sequences checks articles content not much most methods more knowledge industry information information channels channels references learning help search Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Technology NVidia Microsoft Huawei