How can I convert this PHP code to JavaScript?
$string = "string How Long is a Piece of String?";
if (strlen($string) < 5)
{
echo "string is less than 5";
}
else
{
echo "string is more than 5";
}
How can I convert this PHP code to JavaScript?
$string = "string How Long is a Piece of String?";
if (strlen($string) < 5)
{
echo "string is less than 5";
}
else
{
echo "string is more than 5";
}
I assume this is just a really convoluted, badly explained, typo-ridden way of asking how to get the length of a string in JavaScript. If that's the case, just check the length property of the string, like this:
var str = 'How long is a piece of string?';
if (str.length < 5) {
alert('String is less than 5');
} else {
alert('String is greater than or equal to 5');
}
If this is not what you're asking, you really need to clarify the question.