Concat to Safely Join Arrays

by andypotanin

JavaScript

var one = Array.prototype.concat( [ 'i', 'am', 'array' ] ).join( '.' );
var two = Array.prototype.concat( [ 'also', 'array' ], [ 'blah', ['nested' ] ] ).join( '.' );
var three = Array.prototype.concat( 'not-an-array' ).join( '.' );
var four = Array.prototype.concat( { 'asf': 'asdfasfds' } ).join( '.' );

console.log( typeof one, one ); // -> i.am.array  
console.log( typeof two, two ); // -> string also.array.blah.nested
console.log( typeof three, three ); // -> string not-an-array
console.log( typeof four, four ); // -> string [object Object]