Skip to content

Instantly share code, notes, and snippets.

@shanecp
Created March 31, 2015 06:02
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 shanecp/497b59ec060c966e46a9 to your computer and use it in GitHub Desktop.
Save shanecp/497b59ec060c966e46a9 to your computer and use it in GitHub Desktop.
LoDash - extension for implode (similar to PHP function)
_.mixin({
implode: function (glue, collection) {
glue = glue || '';
if (!_.isArray(collection)) return false;
if (collection.length == 1) return collection[0];
var returnString = '';
for (var i = 0, len = collection.length; i < len; i++) {
if (i !== 0) returnString += glue;
returnString += collection[i];
}
return returnString;
}
});
@rderks88
Copy link

Thank you very much for this snippet. Helped me big time!

@Artem-Schander
Copy link

nice, but why not array.join() ?
https://www.w3schools.com/jsref/jsref_join.asp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment