Created
December 9, 2020 20:57
-
-
Save DoctorDerek/79ef16fd54cd4b5b542503debff66cdc to your computer and use it in GitHub Desktop.
Method 1 - Array.prototype.concat()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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