JavaScript中的String()函数与示例

String()函数 (String() function)

String() function is a predefined global function in JavaScript, it is used to convert an object to the string.

String()函数是JavaScript中预定义的全局函数,用于将对象转换为字符串。

Example:

例:

In this example, we are going to convert different object’s values to the string.

在此示例中,我们将把不同对象的值转换为字符串。

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
	<script>		
		var a = "10";	
		var b = "10 20";
		var c = "1234 Hello";
		var d = "Hello 1234";
		var e = true;	
		var f = new Date();
		
		//converting values to string using String() function
		document.write("String(a) = " + String(a) + "<br>");
		document.write("String(b) = " + String(b) + "<br>");
		document.write("String(c) = " + String(c) + "<br>");
		document.write("String(d) = " + String(d) + "<br>");
		document.write("String(e) = " + String(e) + "<br>");
		document.write("String(f) = " + String(f) + "<br>");
	</script>
</body>
</html>

Output

输出量

String(a) = 10
String(b) = 10 20
String(c) = 1234 Hello
String(d) = Hello 1234
String(e) = true
String(f) = Sat Feb 02 2019 23:03:12 GMT+0530 (India Standard Time)


翻译自: https://www.includehelp.com/code-snippets/String-function-with-example-in-javascript.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值