Left function in Javascript provides the same functionaliy provided by the left() function in VBScript. Below is the Javascript Left function code.
Left(str, n): Returns 'n' number of Characters starting from the left of the string 'str'
Note: Use "Left" and not "left"(lower case) while calling the function.
<script language="javascript" type="text/javascript">
function Left(str, n)
{
if (n <= 0)
return "";
else if (n > String(str).length)
return str;
else
return String(str).substring(0,n);
}
</script>
Example:alert(Left("Expertsforge", 2))
Output:Ex
You can also see
Right() function in Javascript