Sling Academy
Home/JavaScript/Page 82

JavaScript

How to create a Map object in JavaScript

Updated: Mar 22, 2023
Map objects were added to JavaScript as part of the ECMAScript 2015 (ES6) standard. They are collections of key-value pairs where the keys can be any value (including functions, objects, or any primitive), and the values can be any value......

JavaScript: Create/Access Object Properties with Variable Keys

Updated: Mar 22, 2023
In JavaScript, you can create and access object properties dynamically by using variable keys. This allows you to create more dynamic and flexible code. In this short and straightforward article, we will explore more than one way to do......

How to Pass a JavaScript Array within a Query String

Updated: Mar 22, 2023
A query string is part of a URL (Uniform Resource Locator) that contains data or parameters to be passed to a web application. The query string starts with a question mark (?) and is followed by key-value pairs separated by an ampersand......

JavaScript: Update/Replace a Specific Element in an Array

Updated: Mar 22, 2023
This quick and straightforward article shows you a couple of different ways to update or replace a specific element in an array in modern JavaScript. Using array[index] syntax You can directly access an element in an array using its......
JavaScript: Programmatically Disable/Enable a Text Input

JavaScript: Programmatically Disable/Enable a Text Input

Updated: Mar 20, 2023
Quick Overview To programmatically disable or enable a text input with pure JavaScript, you can set the disabled property of the text input element to true or false, respectively, like this: // To disable an input with......
JavaScript: How to Programmatically Scroll Inside a Div

JavaScript: How to Programmatically Scroll Inside a Div

Updated: Mar 20, 2023
This article shows you how to programmatically scroll in inside a div element with vanilla JavaScript. Note that this div element needs to have CSS overflow: scroll or overflow-y: scroll for things to work......

JavaScript: Checking if a Key/Value Exists in an Object

Updated: Mar 20, 2023
This article shows you how to check whether a key or a value exists in a given object in JavaScript. Checking If a Key Exists The in operator can be used to determine if a key exists in an object. Example: const obj = { ......

JavaScript: How to append/prepend/insert elements to an array

Updated: Mar 20, 2023
This short and straightforward article shows you how to append, prepend, and insert new elements to an existing array in modern JavaScript. Appending Elements Appending a Single Element In order to append an element to the end of......
Using JavaScript classes to model and validate data

Using JavaScript classes to model and validate data

Updated: Mar 20, 2023
JavaScript classes are a way of defining and creating objects with properties and methods. You can use JavaScript classes to model and validate data by defining the data structure, validation rules, and methods inside the class. A......

5 Ways to Convert an Array to an Object in JavaScript

Updated: Mar 19, 2023
In JavaScript, an array is a collection of items, while an object is a collection of key-value pairs. Sometimes, it can be useful to convert an array to an object to make it easier to access specific items. This practical, example-based......
JavaScript: Find the mode of an array (the most common element)

JavaScript: Find the mode of an array (the most common element)

Updated: Mar 17, 2023
Introduction The mode of an array is the most frequently occurring element in the array. It is one of the measures of central tendency, along with the mean and median. The mode can be used to describe the typical value or the most......

JavaScript: Remove all occurrences of a value from an array

Updated: Mar 17, 2023
When working with JavaScript arrays, there might be cases where you need to delete all elements that match a particular value and leave behind only the elements that do not match that value. This concise, practical article shows you a......