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
// Usando o clássico método String.prototype.split() | |
const title = 'Book'; | |
// É necessário string vazia em argumento | |
console.log(title.split('')); // ['B', 'o', 'o', 'k'] | |
// split sem argumento vai retornar um array com uma única string | |
console.log(title.split()); // ['Book'] | |
// Usando Array.from() | |
const title = 'Book'; | |
console.log(Array.from(title)); // ['B', 'o', 'o', 'k'] |
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
const pessoa = { | |
nome: 'John Connor', | |
twitter: '@john' | |
}; | |
Object.values(pessoa) | |
.toString() | |
.includes('Connor'); |
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
const conteudo = '<h1>JavaScript</h1> <h2>é o melhor!</h2>'; | |
const texto = conteudo.replace(/<[a-zA-Z/][^>]*>/g, ''); | |
console.log(texto); // "JavaScript é o melhor!" |
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
String.prototype.slugify = function() { | |
return this.toLowerCase().replace(/\s/g, '-').trim(); | |
} | |
"Escrevendo JavaScript Melhor".slugify(); | |
// "escrevendo-javascript-melhor" |
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
function slugify(content) { | |
return content.toLowerCase().replace(/\s/g, '-').trim(); | |
} | |
slugify("Escrevendo JavaScript Melhor"); | |
// "escrevendo-javascript-melhor" |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Simple Command Voice</title> | |
</head> | |
<body> | |
<p id="output"></p> | |
<button id="start">Click and say something!</button> | |
<script> | |
(() => { |