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
{"lastUpload":"2020-08-19T21:35:08.705Z","extensionVersion":"v3.4.3"} |
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. create a message | |
const message = 'This is my message.'; | |
// 2. replace message with new thing | |
// this creates a brand new string. does not change the original variable (message) | |
const newMessage = message.replace('message', 'new thing'); | |
// 3. output: This is my new thing. | |
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); |
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
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
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 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
// 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); |
OlderNewer