Skip to content

Instantly share code, notes, and snippets.

@EricDosReis
Created January 10, 2019 14:43
Show Gist options
  • Save EricDosReis/cb756c4a8cf06fc0411f16cf9bfbca9d to your computer and use it in GitHub Desktop.
Save EricDosReis/cb756c4a8cf06fc0411f16cf9bfbca9d to your computer and use it in GitHub Desktop.
Javascript String snippets
const skater = {
nome: 'Corey Duffel',
twitter: '@duffel'
};
function containsStringValue(object, value) {
return Object.values(object)
.toString()
.includes(value);
}
containsStringValue(skater, 'Duffel');
// true
function slugify(content) {
return content.toLowerCase().replace(/\s/g, '-').trim();
}
slugify('JavaScript is the best');
// "javascript-is-the-best"
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