본문 바로가기

Dev. Web/JavaScript Jquery

[JS] 배열 합치기, join 응용

var buffer = {
    entries : [],
    add : function(s) {
        this.entries.push(s);
    },
    concat : function() {
        return this.entries.join("");
    }
};


var source = ["867", "-", "5309"];
source.forEach(function(s) {
    buffer.add(s);
});
buffer.entries.join("");

 

result : "867-5309"