Home  >  Article  >  Web Front-end  >  JavaScript method toLocaleString() to convert an array into a local string

JavaScript method toLocaleString() to convert an array into a local string

黄舟
黄舟Original
2017-11-04 09:34:321679browse

Definition and Usage

Convert an array to a local string.

Syntax

arrayObject.toLocaleString()

Return value

The local string representation of arrayObject.

Instructions

First call the toLocaleString() method of each array element, and then use the region-specific delimiter to concatenate the generated strings to form a string .

Example

<script type="text/javascript">

var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"

document.write(arr.toLocaleString())

</script>

Output:

George, John, Thomas

This code is used to learn the toLocaleString method of JavaScript, use the toLocaleString method of JS to obtain the current computer time, and convert the result: "current The local system time is:" is displayed in the Body area of ​​the web page.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<title>使用toLocaleString获取本地时间</title>
</head>
<body background="temp.JPG">
<script language="javascript">
var now = new Date();
hours = now.getHours();
if (hours < 25)
{
document.write("<font size = 6pt face = 黑体 color = ff9900>"+"当前本地系统时间为:"+now.toLocaleString()+"</font>");
}
</script>
</body>
</html>


The above is the detailed content of JavaScript method toLocaleString() to convert an array into a local string. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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