<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/sources/30seconds/best-of/2022/07" -->

---
title: Best 30 seconds of code posts — July 2022 | daily.dev
description: The most upvoted 30 seconds of code posts from July 2022, curated by the daily.dev community.
canonical: https://daily.dev/sources/30seconds/best-of/2022/07
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:url: https://daily.dev/sources/30seconds/best-of/2022/07
og:type: website
og:site_name: daily.dev
og:title: Best 30 seconds of code posts — July 2022 | daily.dev
og:description: The most upvoted 30 seconds of code posts from July 2022, curated by the daily.dev community.
og:image: https://media.daily.dev/image/upload/s--VAY5ToZt--/f_auto/v1724209435/public/daily.dev%20-%20open%20graph
---

# Best of 30 seconds of code — July 2022

1. 1  
[](https://daily.dev/posts/30-seconds-of-code-pj0utkwhw "30 seconds of code")  
Article  
![Avatar of 30seconds](https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/197d6538eea141d7a2fb4177234e9d89)30 seconds of code · 4y  
30 seconds of code  
Get elements bigger than viewport JavaScript, Browser Returns an array of HTML elements whose width is larger than that of the viewport's. Smoothly scrolls the element on which it's called into the visible area of the browser window. Subtract the two values to get the width of the vertical scrollbar.  
60  
5
2. 2  
[](https://daily.dev/posts/lazy-loading-image-tfdatyl35 "Lazy-loading image")  
Article  
![Avatar of 30seconds](https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/197d6538eea141d7a2fb4177234e9d89)30 seconds of code · 4y  
Lazy-loading image  
Use the useState() hook to create a stateful value that indicates if the image has been loaded. If not, create a new and use to observer the element. Use the return value of the hook to clean up when the component unmounts.  
14  
1
3. 3  
[](https://daily.dev/posts/replace-all-occurrences-of-a-string-in-javascript-chcg1c-ui "Replace all occurrences of a string in JavaScript")  
Article  
![Avatar of 30seconds](https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/197d6538eea141d7a2fb4177234e9d89)30 seconds of code · 4y  
Replace all occurrences of a string in JavaScript  
String.prototype.replaceAll() can be used to replace all occurrences of a string in another string with relative ease. It's supported by all JavaScript engines, old and new, and is very similar to String. prototype.replace all() . While this method doesn't replace all. occurrences, it supports regular expressions. The only issue is that special characters need to be escaped, so that they are matched correctly.  
10

[See all 30 seconds of code archives](/sources/30seconds/best-of)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@graph":[{"@type":"CollectionPage","@id":"https://daily.dev/sources/30seconds/best-of/2022/07#page","url":"https://daily.dev/sources/30seconds/best-of/2022/07","name":"Best 30 seconds of code Posts — July 2022","description":"The most upvoted 30 seconds of code posts from July 2022, curated by the daily.dev community.","isPartOf":{"@type":"WebSite","url":"https://daily.dev"}},{"@type":"ItemList","@id":"https://daily.dev/sources/30seconds/best-of/2022/07#items","numberOfItems":3,"itemListElement":[{"@type":"ListItem","position":1,"url":"https://daily.dev/posts/30-seconds-of-code-pj0utkwhw","name":"30 seconds of code"},{"@type":"ListItem","position":2,"url":"https://daily.dev/posts/lazy-loading-image-tfdatyl35","name":"Lazy-loading image"},{"@type":"ListItem","position":3,"url":"https://daily.dev/posts/replace-all-occurrences-of-a-string-in-javascript-chcg1c-ui","name":"Replace all occurrences of a string in JavaScript"}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Sources","item":"https://daily.dev/sources"},{"@type":"ListItem","position":3,"name":"30 seconds of code","item":"https://daily.dev/sources/30seconds"},{"@type":"ListItem","position":4,"name":"Best of","item":"https://daily.dev/sources/30seconds/best-of"},{"@type":"ListItem","position":5,"name":"July 2022"}]}]}
```

