Tag: array

Fill an Array with Initial Values in JavaScript

Arrays can be initialised with data in a variety of ways in JavaScript. Let’s examine which methods are the easiest and most popular in this post.   Read this blog post or watch the video below to learn more about different ways to fill an array with initial values in JavaScript. #1 Fill an array with primitives Let’s say, you want to initialize an array of elements 5 with the number 1. You can use the array.fill(initialValue) method to initialize an array. This method will return the modified array. The thing that you need to keep in mind is the...

Read More

Sparse vs Dense Arrays in JavaScript

Arrays in JavaScript is a very important concept. Developers are dealing with Arrays like creating, manipulating etc almost every day while implementing logics. Arrays are very easy to understand in JavaScript. An array is a special variable, which can hold more than one value But do you know that Arrays can hold nothing i.e. it is possible to create hole in an Array? In this post, I will be discussing about Sparse and Dense Arrays. Also I will be talking about how to create them and what you can do with this type of arrays. I have written a...

Read More

Group Arrays in JavaScript using Array.GroupBy

JavaScript continuously enriches its standard library on strings and arrays. In today’s post, I will be discussing the new array group proposal which is currently at stage 3. This new proposal introduces new methods array.groupBy() and array.groupByToMap(). You can get their polyfills from the core-js library. Let’s see examples below to understand how these methods work.   Read this blog post or watch the video below to learn more about the JavaScript array.groupBy() and array.groupByToMap() method. array.groupBy() Let’s say you have the below list of countries, where each country is an object with 2 properties name and continent. const countries =...

Read More
Loading

Archives