Created
January 10, 2019 14:43
-
-
Save EricDosReis/cb756c4a8cf06fc0411f16cf9bfbca9d to your computer and use it in GitHub Desktop.
Javascript String snippets
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 skater = { | |
nome: 'Corey Duffel', | |
twitter: '@duffel' | |
}; | |
function containsStringValue(object, value) { | |
return Object.values(object) | |
.toString() | |
.includes(value); | |
} | |
containsStringValue(skater, 'Duffel'); | |
// true |
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
function slugify(content) { | |
return content.toLowerCase().replace(/\s/g, '-').trim(); | |
} | |
slugify('JavaScript is the best'); | |
// "javascript-is-the-best" |
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 content = '<h1>JavaScript</h1> <h2>is the best!</h2>'; | |
function stringFromHTMLTag(content) { | |
return content.replace(/<[a-zA-Z/][^>]*>/g, ''); | |
} | |
stringFromHTMLTag(content); | |
// "Javascript is the best" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment