{"id":310,"date":"2020-10-31T10:11:11","date_gmt":"2020-10-31T13:11:11","guid":{"rendered":"http:\/\/fabiobrandao.net.br\/blog\/?p=310"},"modified":"2023-03-12T00:17:42","modified_gmt":"2023-03-12T03:17:42","slug":"javascript-verificar-se-string-contem-palavra","status":"publish","type":"post","link":"https:\/\/fabiobrandao.net.br\/blog\/javascript-e-bivliotecas\/javascript-verificar-se-string-contem-palavra\/","title":{"rendered":"JavaScript &#8211; Verificar se string cont\u00e9m palavra"},"content":{"rendered":"<p>Para verificar se uma string cont\u00e9m uma palavra com JavaScript utilize o m\u00e9todo <strong>includes()<\/strong>. O m\u00e9todo <strong>includes()<\/strong> retorna <em><strong>true<\/strong><\/em> se a string conter as palavras desejadas ou <em><strong>false<\/strong> <\/em>caso as palavras n\u00e3o sejam encontradas. O m\u00e9todo <strong>includes()<\/strong> \u00e9 case sensitive, diferenciando mai\u00fasculas de min\u00fasculas.<\/p>\n<p>Veja um exemplo de como verificar se uma palavra existe na url:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\tvar currentUrl = window.location.href.toLowerCase();\r\n\tif (currentUrl.includes(&quot;history&quot;)) {\r\n\t\talert('Palavra &quot;history&quot; encontrada na URL');\r\n\t}\r\n\telse\r\n\t{\r\n\t\talert('Palavra &quot;history&quot; n\u00e3o foi encontrada na URL');\r\n\t}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Para verificar se uma string cont\u00e9m uma palavra com JavaScript utilize o m\u00e9todo includes(). O m\u00e9todo includes() retorna true se a string conter as palavras desejadas ou false caso as&#8230; <\/p>\n","protected":false},"author":1,"featured_media":388,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[69],"tags":[71,4,70],"class_list":["post-310","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript-e-bivliotecas","tag-includes","tag-javascript","tag-string"],"_links":{"self":[{"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/posts\/310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/comments?post=310"}],"version-history":[{"count":2,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/posts\/310\/revisions"}],"predecessor-version":[{"id":389,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/posts\/310\/revisions\/389"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/media\/388"}],"wp:attachment":[{"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/media?parent=310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/categories?post=310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fabiobrandao.net.br\/blog\/wp-json\/wp\/v2\/tags?post=310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}