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

How to use contains in js

下次还敢
Release: 2024-05-08 23:45:24
Original
1403 people have browsed it

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template