Javascript

How to Clear a Javascript Object

Today we dive deep into the art of clearing objects in JavaScript. This comprehensive guide will cover different property types (inherited, enumerable), various techniques for effectively resetting or clearing JavaScript objects, including simple objects, nested objects, and those with non-enumerable properties, and immutability. We’ll also address common pitfalls, best practices and a nice Practice Question

How to get the first N elements of an Array in JavaScript

In this blog you will understand how to get the first N javascript array elements, common errors, and a fun coding problem to sharpen your skills. Ways to access first n elements of javascript array The slice() Method: My Preferred Choice to get first N elements of JS array The slice() method is a versatile

How to add Key/Value pairs to a Map in JavaScript

In this blog you will understand how to efficiently add key/value pairs to a Javascript Map, common errors, and a fun coding problem to polish your skills. Refresher: Js Map and Map vs Object Before diving into the methods, let’s briefly recap what Maps are in JavaScript. Maps are collections that store key-value pairs. They

How to Iterate over Set in Javascript

Set, a Javascript data structure, is a collection of unique values, providing a powerful tool for scenarios where distinct elements matter. But how do you iterate on a Javascript Set? In this blogpost, you will explore code samples to iterate set in Javascript, common errors, and a fun coding problem to polish your skills. Iteration

How to update a Value in a Map in JavaScript

JavaScript Maps provide an elegant way to store key-value pairs. But how do we update values in a Map. Whether you’re a JavaScript beginner or a seasoned developer, you will explore code samples for frequent cases, common errors, and a fun coding problem to polish your skills. Understanding JavaScript Maps A Map is a collection

Mastering Browser LocalStorage Javascript: Looping over all stored keys

Understanding localStorage is crucial for developers working with web applications. This local storage solution enables the storage of key-value pairs in a user’s browser, persisting data even after the browser is closed. In this guide, we’ll explore various techniques for iterating over localStorage keys and also common mistakes. What is localStorage() localStorage is a web

Get All the First Letters of Words in a String

In this blogpost, we’ll see how to get the first characters from all the words in a Javascript string. Method 1: Using .split(), .map(), and .join() This classic function trio can be used to: Explanation: Method 2: Using Regular Expressions For regex enthusiasts, we can get all words using regex pattern /b/w, and then like

How to modify all the Array elements in JavaScript

Updating or modifying all the array elements is a frequent need in Javascript (or even React JS)? in this blogpost, lets see how can we do it. Using Array.map() The Array.map() can create a new array after applying a (mapping) function to each element in the original array. Let’s see how it helps us update

How to get the Index of Max/Min Values in JavaScript Arrays

Dealing with mood swings of Javascript arrays? In this blog post, you will understand how to find the Highs (global maximas) and Lows (global minimas) of JS array. Lets begin. Getting Max Value(s) Getting the first index using Math.max() and Array.indexOf() Explanation: Getting all the indices using loop and Math.max() Employ a loop to iterate

How to Convert a Map to JSON in JavaScript

Welcome, fellow coders! In this blog, we’ll see how to convert a map to JSON in JS. Shall we? Method 1: JSON.stringify This method takes an object, and through the magic of serialization, transforms it into a JSON string. Explanation: Method 2: Array.from() Array.from() assists in converting a Map to an array of key-value pairs,

Scroll to Top