Home > Web Front-end > JS Tutorial > body text

How to convert object into string in javascript

藏色散人
Release: 2023-01-04 09:33:52
Original
3104 people have browsed it

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. .

How to convert object into string in javascript

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)
Copy after login

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>
Copy after login

Output:

1337
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template