“Jak sprawdzić, czy ciąg jest w ciągu JS” Kod odpowiedzi

Jak sprawdzić, czy ciąg jest w ciągu JS

// Example 1:
const string = "Hello world!";

n = string.includes("world");

// n is equal to true in Example 1

// Example 2:
const string = "Hello world!, I am Kavyansh";

n = string.includes("I am Aman");
// n is equal to false in Example 2
// Note: the .includes method is case sensitive
Funyn Kayvanhs Khiatan

JavaScript zawiera podłoże

var str = "We got a poop cleanup on isle 4.";
if(str.indexOf("poop") !== -1){
	alert("Not again");
}
//use indexOf (it returns position of substring or -1 if not found)
Grepper

Sprawdź, czy wartość to ciąg JavaScript

let eventValue = event.target.value;

    if (/^\d+$/.test(eventValue)) {
      eventValue = parseInt(eventValue, 10);
    }

//If value is a string, it converts to integer. 

//Otherwise it remains integer.
Rey

Odpowiedzi podobne do “Jak sprawdzić, czy ciąg jest w ciągu JS”

Pytania podobne do “Jak sprawdzić, czy ciąg jest w ciągu JS”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu