- Array.forEach( function(currentValue, index, arr) {} ); — forEach() method calls a function for each element in an array.
- Array Length in JavaScript — In JavaScript, <array>.length returns the total number of item.
- Check if the variable is object or not — typeof <variable name> shows its type in string in JavaScript
- Check whether a checkbox is checked in Javascript — Checkbox object in HTML has a property checked as boolean - it has true or false, so javascript can check its status easily.
- Count number of lines in the string in Javascript — Counting number of lines in the string in Javascript is able to implement by regular expression.
- Create empty array and add its elements in JavaScript — You have two main ways to create empty array: const myArray=[] or const myArray = new Array();
- Error count when loading remote JS script when considering Ad Blocker Detector — Ad Blocker usually blocks the browser to load remote scripts and it causes error on the browser. In this case, we may able to count the number of errors when the page does not load the javascript as designed. Ad Blocker Extension blocks loading remote script in the browser based on its filtering logic, so we can assume if the Ad Blocker is installed or not by counting number of scripts blocked.
- Extract Filename or Path from URL in JavaScript — You can get filename and its path easily by the string operation function included in JavaScript.
- file_exists( url ) to check availability of the file with javascript without jQuery — XMLHttpRequest() enables you to check file availability by its methods: open, send and status.
- Find images in HTML with javascript — document.getElementByTagName() enables you to find objects based in tag name like img, a, ...
- Get file extension in Javascript
- Input Text readOnly Property in Javascript — Set a text field to read-only in javascript
- Loading javascript file conditionally — If you need to load javascript by the case like domain name, you can do that by getElementByTagName() and appendChild(). For instance, you can run application by the screen width.
- Load JSON file parsed from the text in JavaScript Variable
- Load remote javascript code dynamically — A common approach load remote JS code is to use <script src="..."></script>, but sometimes you will be required to load the remote JavaScript code dynamically. Then you can simple do it by creating script element by document.createElement('script')
- Open window in the center of the screen
- pathinfo() to parse protocol, hostname and pathname from the given url path with javascript — createElement() with javascript enables you to have all the necessary properties easily
- Play beep sound in Javascript — Javascript does not have a built-in function to produce a beep sound directly. However, you can achieve a similar effect using the HTML5 Audio API to play a short audio file or use the 'navigator.vibrate()' API to vibrate the device if it supports it.
- Recognizing a 404 not found error in an iframe — When the iframe fails to load due to a 404 error or any other error, the 'onerror' event will be triggered, alloing you to handle the situation accordingly.
- Remove all associated child objects to avoid memory leaks — To avoid memory leaks in JavaScript, you need to make sure that you remove all references to an object when you're done with it. This includes event listeners, timers, and any other objects that might hold references to the object you want to clean up.
- Run a specific function by certain interval — The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds). The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed. The ID value returned by setInterval() is used as the parameter for the clearInterval(obj) method.
- Run a specific function by timer in Javascript — Javascript provides a straightforward function setTimeout() to implement timer-based application easily.
- Stop timer in Javascript — clearTimeout() can stop the running timer based on the variable. Below code shows the simple example to stop running timer.
- String to ISO Dates, Date to String in Javascript — If you want to put date information as string like "2020-07-30" to date in javascript, bingo! - it works correctly.
Overview
Content Tools