{"id":43,"date":"2023-06-09T08:53:02","date_gmt":"2023-06-09T08:53:02","guid":{"rendered":"https:\/\/tutorialbydevelopers.com\/?p=43"},"modified":"2023-06-11T05:39:29","modified_gmt":"2023-06-11T05:39:29","slug":"top-10-most-used-javascript-one-liner-for-web-developers","status":"publish","type":"post","link":"https:\/\/tutorialbydevelopers.com\/index.php\/2023\/06\/09\/top-10-most-used-javascript-one-liner-for-web-developers\/","title":{"rendered":"Top 10 most used JavaScript one liner for Web Developers"},"content":{"rendered":"\n<p>Here you will find the Most commonly used Javascript one liners to ease your daily coding stuff.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Select all elements with a particular class: document.querySelectorAll(&#8216;.className&#8217;);<\/li>\n\n\n\n<li>Get the current URL: window.location.href;<\/li>\n\n\n\n<li>Detect if an element is visible on the screen:<br>let element = document.querySelector(&#8216;#some_element&#8217;);<br>element.getBoundingClientRect().top &lt; window.innerHeight<\/li>\n\n\n\n<li>Check if a string contains another string: (str.includes(subString))<\/li>\n\n\n\n<li>Convert a NodeList to an array: [\u2026nodeList]<\/li>\n\n\n\n<li>Load external scripts dynamically:<br>let script = document.createElement(&#8216;script&#8217;);<br>script.src = &#8216;path\/to\/script.js&#8217;;<br>document.body.appendChild(script);<\/li>\n\n\n\n<li>Get the page title: document.title;<\/li>\n\n\n\n<li>Copy text to clipboard: navigator.clipboard.writeText(data)<\/li>\n\n\n\n<li>Format a number with specific decimal points: new Intl.NumberFormat(&#8216;en-US&#8217;, {maximumFractionDigits: 2}).format(100.1234);<\/li>\n\n\n\n<li>Get current date and time: new Date().toISOString();<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Here you will find the Most commonly used Javascript one liners to ease your daily coding stuff.<\/p>\n","protected":false},"author":1,"featured_media":55,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,6],"tags":[12,7,11,9],"class_list":["post-43","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers-life","category-website-development","tag-angular","tag-html","tag-javascript","tag-web-developer"],"featured_image_urls":{"full":["https:\/\/tutorialbydevelopers.com\/wp-content\/uploads\/2023\/06\/Top-10-One-liners-of-JavaScript.png",485,494,false],"thumbnail":["https:\/\/tutorialbydevelopers.com\/wp-content\/uploads\/2023\/06\/Top-10-One-liners-of-JavaScript-150x150.png",150,150,true],"medium":["https:\/\/tutorialbydevelopers.com\/wp-content\/uploads\/2023\/06\/Top-10-One-liners-of-JavaScript-295x300.png",295,300,true],"medium_large":["https:\/\/tutorialbydevelopers.com\/wp-content\/uploads\/2023\/06\/Top-10-One-liners-of-JavaScript.png",485,494,false],"large":["https:\/\/tutorialbydevelopers.com\/wp-content\/uploads\/2023\/06\/Top-10-One-liners-of-JavaScript.png",485,494,false],"1536x1536":["https:\/\/tutorialbydevelopers.com\/wp-content\/uploads\/2023\/06\/Top-10-One-liners-of-JavaScript.png",485,494,false],"2048x2048":["https:\/\/tutorialbydevelopers.com\/wp-content\/uploads\/2023\/06\/Top-10-One-liners-of-JavaScript.png",485,494,false],"morenews-featured":["https:\/\/tutorialbydevelopers.com\/wp-content\/uploads\/2023\/06\/Top-10-One-liners-of-JavaScript.png",485,494,false],"morenews-large":["https:\/\/tutorialbydevelopers.com\/wp-content\/uploads\/2023\/06\/Top-10-One-liners-of-JavaScript.png",485,494,false],"morenews-medium":["https:\/\/tutorialbydevelopers.com\/wp-content\/uploads\/2023\/06\/Top-10-One-liners-of-JavaScript.png",403,410,false]},"author_info":{"info":["Rishabh Awasthi"]},"category_info":"<a href=\"https:\/\/tutorialbydevelopers.com\/index.php\/category\/developers-life\/\" rel=\"category tag\">Developers Life<\/a> <a href=\"https:\/\/tutorialbydevelopers.com\/index.php\/category\/website-development\/\" rel=\"category tag\">Website Development<\/a>","tag_info":"Website Development","comment_count":"0","_links":{"self":[{"href":"https:\/\/tutorialbydevelopers.com\/index.php\/wp-json\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorialbydevelopers.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorialbydevelopers.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorialbydevelopers.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorialbydevelopers.com\/index.php\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":2,"href":"https:\/\/tutorialbydevelopers.com\/index.php\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":57,"href":"https:\/\/tutorialbydevelopers.com\/index.php\/wp-json\/wp\/v2\/posts\/43\/revisions\/57"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tutorialbydevelopers.com\/index.php\/wp-json\/wp\/v2\/media\/55"}],"wp:attachment":[{"href":"https:\/\/tutorialbydevelopers.com\/index.php\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorialbydevelopers.com\/index.php\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorialbydevelopers.com\/index.php\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}