JavaScript 陣列.toLocaleString() 函式


JavaScript 陣列.toLocaleString() 函式返回陣列的元素作為字串,並用特定於區域設定的字串(例如逗號)分隔。它可以將區域設定作為引數,該引數指定要將字串轉換為其中的語言標記。

以下是 array.toLocaleString() 函式的程式碼

示例

 即時演示

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
   font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.sample {
   font-size: 20px;
   font-weight: 500;
}
</style>
</head>
<body>
<h1>JavaScript array.toLocaleString()</h1>
<div class="sample"></div>
<button class="Btn">CLICK HERE</button>
<h3>Click on the above button to convert the array to UK locale string</h3>
<script>
let fillEle = document.querySelector(".sample");
let arr = [1, 3, new Date()];
fillEle.innerHTML = arr;
document.querySelector(".Btn").addEventListener("click", () => {
   arr = arr.toLocaleString("en-GB");
   fillEle.innerHTML = arr;
});
</script>
</body>
</html>

輸出

單擊“點選此處”按鈕後 −

更新日期: 2020 年 5 月 6 日

96 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.