Home  >  Article  >  Web Front-end  >  How to use contains in js

How to use contains in js

下次还敢
下次还敢Original
2024-05-08 23:45:241298browse

The contains() method in JavaScript is used to determine whether a string contains another substring. Returns true if included; otherwise, returns false.

How to use contains in js

contains() usage in JavaScript

Answer the question:
contains () method is used to determine whether a string contains another substring. Returns true if included; otherwise, returns false.

Expand answer:

Grammar:

<code>string.contains(substring)</code>

Among them,

  • string is the string to search for.
  • substring is the substring to be found.

Parameters:

Parameters Description
substring The substring to be found

Return value:

Return value Description
true If the string contains subcharacters String
false If the string does not contain a substring

Example:

<code>const str = "Hello, World!";

console.log(str.includes("Hello")); // 输出:true
console.log(str.includes("Universe")); // 输出:false</code>

Note:

  • contains() method is not case sensitive.
  • Always returns true if the substring is the empty string.
  • contains() method is a built-in method in JavaScript and can be used without importing any library.

The above is the detailed content of How to use contains in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:The role of const in jsNext article:The role of const in js