JavaScript Compruebe si cadena
if (typeof myVar === 'string' || myVar instanceof String)
// it's a string
else
// it's something else
Elegant Elk
if (typeof myVar === 'string' || myVar instanceof String)
// it's a string
else
// it's something else
var value = "test string"
console.log(typeof value === "string")
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"
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.