This file contains 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
const months = ['March', 'April', 'May']; | |
const otherMonths = ['June', 'July']; | |
const totalMonths = months.concat(otherMonths); | |
console.log(totalMonths); |
This file contains 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
// we have 2 arrays of people | |
const people = ['chris', 'nick']; | |
const newPeople = ['holly', 'william']; | |
// add them together to create a new array | |
const allPeople = people.concat(newPeople); | |
// output: ['chris', 'nick', 'holly', 'william'] | |
console.log(allPeople); |
This file contains 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
// 1. we have a string | |
const myString = 'hi there. '; | |
// 2. repeat over it 5 times | |
const repeatedString = myString.repeat(5); | |
// 3. output: hi there. hi there. hi there. hi there. hi there. | |
console.log(repeatedString); |
This file contains 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
"🔥✨🚀".repeat(10); |
This file contains 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
const myUrl = 'this\-is\-my\-url'; | |
// myMessage.replace(/\\-/g, '-'); | |
// or | |
const newUrl = myUrl.replace(new RegExp('\-', 'g'), '-'); | |
console.log(newUrl); // this-is-my-url |
This file contains 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
const myMessage = 'this is the sentence to end all sentences'; | |
const newMessage = myMessage.replace(/sentence/g, 'message'); | |
console.log(newMessage); // this is the message to end all messages |
This file contains 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
const myMessage = 'this is the sentence to end all sentences'; | |
const newMessage = myMessage.replace(new RegExp('sentence', 'g'), 'message'); | |
console.log(newMessage); // this is the message to end all messages |
This file contains 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
const myMessage = 'this is the sentence to end all sentences'; | |
const newMessage = myMessage.replace('sentence', 'message'); | |
console.log(newMessage); // this is the message to end all sentences |
This file contains 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
// 1. we have a sentence | |
const message = 'This is my store. In my store we store store store.' | |
// 2. replace all store with shop using a regular expression | |
// normally .replace() will only replace the 1st occurrence | |
const newMessage = message.replace(new RegExp('store', 'g'), 'shop'); | |
// 3. output: This is my shop. In my shop we shop shop shop. | |
console.log(newMessage); |
This file contains 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
// 1. we have a url | |
const url = "http://scotch.io"; | |
// 2. replace http: with https: | |
const httpsUrl = url.replace("http:", "https:"); | |
// 3. output: https://scotch.io | |
console.log(httpsUrl); |