Home > Article > Web Front-end > How to convert object into string in javascript
In JavaScript, you can convert a Number object into a string through the toString() method and return the result; the syntax of this method is "NumberObject.toString(radix)", and the parameter radix represents the base of the number. .
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
The toString() method converts a Number object into a string and returns the result.
Syntax
NumberObject.toString(radix)
Parameters
radix Optional. Specifies the base in which the number is represented, making it an integer between 2 and 36. If this parameter is omitted, base 10 is used. Note, however, that the ECMAScript standard allows implementations to return any value if the parameter is a value other than 10.
Return value
The string representation of the number. For example, when radix is 2, the NumberObject is converted to a string representing the binary value.
Throws
A TypeError exception is thrown when the object calling this method is not a Number.
Example
In this example, we will convert a number to a string:
<script type="text/javascript"> var number = new Number(1337); document.write (number.toString()) </script>
Output:
1337
[Recommended learning: js basic tutorial]
The above is the detailed content of How to convert object into string in javascript. For more information, please follow other related articles on the PHP Chinese website!