La méthode JavaScript Array toLocaleString () renvoie une chaîne représentant les éléments du tableau.
La syntaxe de la toLocaleString()
méthode est:
arr.toLocaleString(locales, options)
Ici, arr est un tableau.
Paramètres toLocaleString ()
La toLocaleString()
méthode prend en compte:
- locales (facultatif) - Une chaîne avec une balise de langue BCP 47, ou un tableau de ces chaînes. Pour en savoir plus, visitez Intl - JavaScript.
- options (facultatif) - Un objet avec des propriétés de configuration.
Valeur renvoyée par toLocaleString ()
- Renvoie une chaîne représentant les éléments du tableau.
Remarque : Cette méthode convertit chaque élément du tableau en chaînes à l'aide de leurs méthodes toLocaleString et les sépare par une virgule.
Exemple: utilisation de la méthode toLocaleString ()
let array = (1, "JavaScript", new Date()); let string = array.toLocaleString(); console.log(string); // 1,JavaScript,7/29/2020, 1:53:29 PM let prices = (689, 100, 4577, 56); // Using locales and options // using Nepali Ruppes currency string format let string1 = prices.toLocaleString("ne-NP", ( style: "currency", currency: "NPR", )); console.log(string1); // NPR 689.00,NPR 100.00,NPR 4,577.00,NPR 56.00
Production
1, JavaScript, 29/07/2020, 1:57:35 NPR 689.00, NPR 100.00, NPR 4.577.00, NPR 56.00
Lecture recommandée: Javascript Array toString ()