Skip to content

Instantly share code, notes, and snippets.

@kflorence
Created January 1, 2013 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kflorence/4424458 to your computer and use it in GitHub Desktop.
Save kflorence/4424458 to your computer and use it in GitHub Desktop.
Simple function for joining non-Array object properties
// join( { one: "one", two: "two" } );
// => "one,two"
function join( obj, separator ) {
var k,
items = [];
if ( typeof obj.join === "function" ) {
items = obj;
} else {
for ( k in obj ) {
if ( obj.hasOwnProperty( k ) ) {
items.push( obj[ k ] );
}
}
}
return items.join( separator );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment