Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DoctorDerek/79ef16fd54cd4b5b542503debff66cdc to your computer and use it in GitHub Desktop.

Select an option

Save DoctorDerek/79ef16fd54cd4b5b542503debff66cdc to your computer and use it in GitHub Desktop.
Method 1 - Array.prototype.concat()
// Joining Two Strings with .concat()
const stringOne = "🎅🤶"
const stringTwo = "👩‍🚀👨‍🚀"
// Use .concat() to join the strings:
console.log(stringOne.concat(stringTwo))
// Output: 🎅🤶👩‍🚀👨‍🚀
// .concat() won't change the string:
console.log(stringOne) // 🎅🤶
console.log(stringTwo) // 👩‍🚀👨‍🚀
// We can use the plus sign + instead:
console.log(stringOne + stringTwo)
// Output: 🎅🤶👩‍🚀👨‍🚀
// The + won't change either string.
// Joining Two Arrays with .concat()
const arrayOne = ["🎅", "🤶"]
const arrayTwo = ["👩‍🚀", "👨‍🚀"]
// Use .concat() to join the arrays:
console.log(arrayOne.concat(arrayTwo))
// Output: ["🎅", "🤶", "👩‍🚀", "👨‍🚀"]
// .concat() doesn't change either array:
console.log(arrayOne) // ["🎅", "🤶"]
console.log(arrayTwo) // ["👩‍🚀", "👨‍🚀"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment