How to convert array to locale string

Description

Array toLocaleString() calls each item's toLocaleString() instead of toString() to get its string value.

Example


var tutorial1 = {
    toLocaleString : function () {// w  ww  . j  av  a  2 s. c  om
        return "Java";
    },
    
    toString : function() {
        return "XML";
    }
};

var tutorial2 = {
    toLocaleString : function () {
        return "HTML";
    },
    
    toString : function() {
        return "CSS";
    }
};

var tutorial = [tutorial1, tutorial2];
console.log(tutorial.toLocaleString()); //Java HTML

The code above generates the following result.





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window