Sling Academy
Home/JavaScript/Page 89

JavaScript

How to use for…in loop in JavaScript: Best practices

Updated: Feb 19, 2023
In JavaScript, the for…in loop is used to iterate over the properties of an object or the indices of an array. It has a similar syntax for both objects and arrays, but there are some differences in how they are used. for…in loops......

JavaScript: 5 ways to create a new array from an old array

Updated: Feb 19, 2023
There are multiple ways to create a true new array from an old array in modern Javascript (ES6 or beyond). Using the spread syntax (shallow copy) This method works perfectly when you try to clone a one-level (or one-dimensional)......

JavaScript: 2 Ways to Sort an Array of Objects by Property Value

Updated: Feb 19, 2023
Sorting data is a common task in programming and isn’t an exception in Javascript. In this article, we will discuss how to sort an array of objects by their property values in 2 different ways: the first one is to write code from......

JavaScript: Ways to Create New Objects from Old Objects

Updated: Feb 19, 2023
As a web developer, you are very likely to find yourself in need of creating new objects from old ones in Javascript when either developing complex projects or just writing some code for small applications. Although the job seems simple......

JavaScript: 6 Ways to Calculate the Sum of an Array

Updated: Feb 19, 2023
This practical, succinct article walks you through three examples that use three different approaches to find the sum of all elements of a given array in Javascript (suppose this array only contains numbers). Without any further ado,......

JavaScript: Convert UTC time to local time and vice versa

Updated: Feb 19, 2023
It is essential for web applications to display the correct time, especially when dealing with multiple time zones. This is where converting between UTC and local time comes in. This article will discuss what UTC and local time are, why......

How to Remove Elements from an Array in JavaScript

Updated: Feb 19, 2023
As a programmer, there might be scenarios where you have to remove specific elements from an array in Javascript. It is important to understand the various techniques available for doing so in order to select the most efficient and......

JavaScript: 3 Ways to Remove a Property from an Object

Updated: Feb 19, 2023
When working with Javascript, there might be cases where it becomes necessary to remove single or multiple properties from a given object. For example, if you are creating an API and need to hide certain sensitive information before......

JavaScript: How to Convert Date Time to Time Ago

Updated: Feb 19, 2023
Time ago is the concept of expressing a time relative to the current time. For example, if it is currently 3 pm and we want to talk about the moment at 1 pm, then we can say 2 hours ago. Time ago is widely used in modern applications like......

JavaScript: Convert timestamp to date time and vice versa

Updated: Feb 19, 2023
This article shows you how to convert Unix timestamp into date time and vice versa in Javascript. Overview Unix timestamp is a numeric value that represents the number of seconds that have elapsed since January 1, 1970, at 00:00:00......

JavaScript: Check if a string contains a substring (4 approaches)

Updated: Feb 19, 2023
This practical article walks you through 4 different ways to check whether a given string contains a substring or not. Without any further ado (like talking about the history of Javascript or explaining what a string is), let’s get......

How to Subtract and Compare 2 Dates in JavaScript

Updated: Feb 19, 2023
This article is about subtracting and comparing 2 dates in Javascript. We’ll have a look at the fundamentals and then walk through several examples of applying that knowledge in practice. Overview There are many scenarios......