Five Ways to Loop Through a JavaScript Array

Learn the different methods to loop through arrays in JavaScript Photo by Zan on Unsplash In JavaScript there are many ways to loop through Array. Loops which can break or skip (continue) an iteration: for while do…while for…in 2. Loops which we cannot break or skip an iteration: forEach Tip: To create an array with a …

Different ways to measure performance in JavaScript

Learn different ways to measure the time it takes to execute programs in JavaScript Image by Aron Visuals To find how much time a function, loop, or any operation takes to execute in JavaScript, we can use one of the following tools: Using console.time and console.timeEnd Using the performance.now method Using online performance testing tools 1. …

Understanding The forEach Method for Arrays in JavaScript

Improve your iteration Photo by Mika Baumeister on Unsplash What is forEach? The forEach method executes the callback function against all element of the array. forEach method in JavaScript Syntax array.forEach(callbackFunction, [, thisArg]); // thisArg is optional arguments for callbackFunction callbackFunction(currentValue, index ,array) { //index, array is optional } The forEach method doesn’t return anything. Let’s start …

15 VS Code Extensions to Save Your Time and Make You a Better Developer

A list of useful VS Code extensions for frontend developers VS Code has a marketplace, and it contains a collection of plugins that can be installed into the text editor to make it more powerful. We can open market place by selecting Extension option in View menu or simply press shift + cmd + X . …

Three ways to merge arrays in JavaScript

Learn different ways to merge array in JavaScript Image by Makarios Tang 1. Using for loop We can loop through the array source array which need to be pushed , then add elements one by one function push(fromArray, toArray) { for(let i = 0, len = fromArray.length; i < len; i++) { toArray.push(fromArray[i]); } return toArray;} var array1 …

How to Install Themes in Chrome Dev Tools — Make the Chrome Console Colorful

This article shows you how to add themes in your Chrome developer console and make it look like your favorite IDE or text editor To make your Chrome dev tool look like your IDE, you need to: Enable the experiment flag Allow custom UI themes in your Chrome. Install a UI Extension (Material Theme) from the …

You Don’t Need Loops in JavaScript

Learn how to remove loops and use higher-order functions like map, reduce, and filter Image by Lysander Yuen Why Are We Replacing Loops? Using higher-order functions will make your code : More readable. Easy to understand. Easy to debug. 1. To Loop Through All Elements and Get an new modified array Using loop: var names = [“Jack”, “Jecci”, “Ram”, …

Generating Random Numbers in JavaScript

It’s more than Math.random() Image by NeONBRAND The Math.random() will generate a pseudo-random floating number (a number with decimals) between 0 (inclusive) and 1 (exclusive). Here, the random number doesn’t mean that you always get a unique number. It generates the same number only after some interval. The interval here is very long, so you …

Detecting Battery Status in JavaScript.

Learn how to detect battery status in JavaScript using Battery Manager. Image by Brett Jordan. The BatteryManager interface provides ways to get information about the system’s battery charge level. We can use the Battery Manager to detect charging state Battery percentage Time needed to charge 100% The remaining time until the battery is completely discharged. First, let’s …

Debug Like a Lion With Chrome’s DevTools

Tips and tricks for using Chrome’s DevTools more effectively Image by Ivan Diaz You can open Chrome’s DevTools with CMD + option + J. Note: This tricks only works in the Chrome console. 1. $_ If you type $_ in the console, it will print the last evaluated expression in the console. Example: 6 + 6 …

Design a site like this with WordPress.com
Get started