Javascript Reference - How to convert array to locale string








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

Example


var tutorial1 = {
    toLocaleString : function () {// w ww .  ja  v a  2s.co  m
        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.