Returns the array as a string with set notation, e.g.: [1,2,3] -> {1,2,3} - Node.js Array

Node.js examples for Array:Swap

Description

Returns the array as a string with set notation, e.g.: [1,2,3] -> {1,2,3}

Demo Code

Array.prototype.set = function () {
    var copy = this.slice();
    copy.sort()//  w ww .  ja v a 2  s  . co  m
    var result = "{" + copy[0];
    for (var i = 1; i < copy.length; i++)
        result += "," + copy[i];
    result += "}";
    return result;
};

Related Tutorials