JavaScript array.toLocaleString() function

JavascriptFront End TechnologyObject Oriented Programming

The JavaScript array.toLocaleString() function returns the elements of an array as a string and are separated by a locale specific string such as comma. It can take locale as parameter which specifies the language tag in which the string is to be converted.

Following is the code for the array.toLocaleString() function


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
body {
   font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
.sample {
   font-size: 20px;
   font-weight: 500;
<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>
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;


On clicking the “CLICK HERE” button −

Published on 06-May-2020 12:20:57