“Sprawdź, czy wartość ciąg JS” Kod odpowiedzi

JavaScript Sprawdź, czy ciąg

if (typeof myVar === 'string' || myVar instanceof String)
// it's a string
else
// it's something else
Elegant Elk

Sprawdź, czy wartość ciąg JS

var value = "test string"
console.log(typeof value === "string")
Salsabeel woh woh

Jeśli zmienna to ciąg JavaScript

var booleanValue = true; 
var numericalValue = 354;
var stringValue = "This is a String";
var stringObject = new String( "This is a String Object" );
alert(typeof booleanValue) // displays "boolean"
alert(typeof numericalValue) // displays "number"
alert(typeof stringValue) // displays "string"
alert(typeof stringObject) // displays "object"
Fragile Flamingo

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 “Sprawdź, czy wartość ciąg JS”

Pytania podobne do “Sprawdź, czy wartość ciąg JS”

Więcej pokrewnych odpowiedzi na “Sprawdź, czy wartość ciąg JS” w JavaScript

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

Przeglądaj inne języki kodu