Complex Manipulations of Javascript Arrays with Javascript Array Methods

A Javascript array is a special type of variable that holds multiple valid Javascript values. They help developers keep related values and objects together, while also providing the ability to change elements independently without affecting any others.

let example0a = ["a", "c", "c", 1, 2, 3];
example0a[1] = "b";
// Array after this change: ["a", "b", "c", 1, 2, 3];

Javascript arrays are distinct from JSON arrays because the contents of Javascript arrays are changeable. Many methods exist to change their contents or make them easier to handle. The Javascript standard defines 10 different methods specifically designed for manipulating Javascript arrays.

Some Javascript array methods change the contents of the array they act upon, while others do not. Some methods return a new array, while others perform an operation and return the length of the resulting array, and yet others return other, operation-appropriate, values.

This article describes each of the Javascript array methods, what they do, and what values they return. The list of methods is presented in order of increasing complexity, starting with those that don’t change an array’s contents.

Continue Reading

Storing User Data with Javascript Cookies

Here’s an interesting revelation about Javascript: Since Javascript is a client-side web development language, it has access to information about a user that other programming languages don’t.

The Javascript standard provides developers the chance to enhance user experiences using that data via Javascript cookies. 

Every web user has heard of a cookie at some point; we have to accept them at most websites we visit. Usually, we choose to accept them because a dialog box blocks our way, and then we go about our day. Those dialog boxes don’t tell us much about what a cookie is, though, and how many of us have really stopped to think about what they are?

In this article, we describe what Javascript cookies are and how they make your web browsing experience more interesting. Then, we’ll go over how developers manipulate and manage Javascript cookies.

Continue Reading

Performing Actions Until a Condition is no Longer True Using Javascript While Loops

The Javascript while loop is a programming construct that executes a set of statements as long as a certain condition is true. While loops are part of a programming statement class called “control statements,” since they influence the logical flow of a program.

The Javascript standard specifies two different types of while loops: the simple while loop and the do-while loop. Although they have similar functions, important differences between them make them useful in slightly different circumstances.

In this article, we define what a Javascript while loop is and how it differs from the do-while loop. This article also covers some caveats when using either of those loops.

Continue Reading

What are Javascript Objects? Containers for Reusable Properties and Behaviors

Javascript is a versatile programming language; you can create short scripts of only a few lines or complex modules that contain many. Developers handling many web pages often need to reuse their Javascript code; copying and pasting scripts between pages is a tedious and error-prone process.

The Javascript standard provides the ability to create reusable code in the form of Javascript objects. Javascript objects provide complex functionality with minimal code, making new scripts easy to maintain and fast to load.

Continue Reading

Javascript Timers and Javascript Wait Functions: Handling Execution Times

Dynamic content, or content that changes when a user interacts with a web page, is an integral part of the modern web experience. Javascript provides web users with a more engaging web experience by making it easy to create dynamic content.

A key aspect of creating dynamic content is making sure that the changing parts of a web page happen at the proper time. When dynamic Javascript effects occur at the wrong times, parts of a web page can become inaccessible, too much content can crowd the screen at once, and users can experience other problems.

The Javascript standard provides two different functions to control dynamic timing: setTimeout() and setInterval(). Each function defines specific times that dynamic events should happen; they work differently and are best used in different contexts..

Continue Reading