Home » Programming » Javascript

Merge Arrays in JavaScript with concat() and push() [Examples]

JavaScript Join Merge Concatenate Arrays

This tutorial will show you the correct ways to merge two or more arrays in JavaScript with the concat method – and provide a warning about how not to merge arrays. Merging/Joining Arrays in JavaScript with the concat()* Method The concat() method exists with one purpose – to merge arrays. concat() Method Syntax array.concat(ARRAYS) Note that: array is the first array of the arrays to be joined ARRAYS should be a comma-separated list of arrays to be added to the first array They will be joined in the order of appearance concat() returns a new array – … Read more

Home » Programming » Javascript

How to Randomize/Shuffle an Array in JavaScript [Examples]

JavaScript Randomize Shuffle Array

This article will show you a few ways, both easy and complex, to randomize/shuffle an array in JavaScript. The Quick and Dirty Way to Randomize an Array If you aren’t too concerned about the probabilities involved, this code is a quick way to randomize the contents of an array: // Function to return a shuffled copy of a given array function shuffle(array) { var shuffled = […array]; // Make a copy of the array to be shuffled so that the original is not altered by … Read more

Home » Programming » Javascript

How to Reverse an Array In JavaScript

JavaScript Reverse Array

This short article will show you how to reverse an array in the JavaScript programming language. What is an Array? An array is a type of variable that holds an ordered list of values. Each value has a position in the array, called the index – and can be accessed by using that index. As an array is ordered, the position matters. Values within arrays will be processed by loops and other data structures in order – so being able to reverse that order is beneficial. Reversing an … Read more

Home » Programming » Javascript

How to use Comments in JavaScript

JavaScript Comments

This short article will explain how and why you should use comments in JavaScript. First up, how to comment. What is a Comment? A comment in programing is one or more lines of text that aren’t interpreted as programming instructions. Instead, the computer skips them when executing your code, completely ignoring them. Therefore, comments don’t have to conform to any valid syntax. They’re just text that you read, and the computer doesn’t. Single-Line Comments in JavaScript Commenting is easy. How easy? This easy: // This is a comment … Read more

Home » Programming » Javascript

JavaScript Libraries We’re Using to Build Apps in 2022

Javascript Libraries

JavaScript libraries take the legwork out of building complex applications. Here are some of the most useful libraries to use in 2021/2022. Once you’ve graduated from ‘Hello World!‘ and understand how JavaScript works, you’ll probably want to dive into building something more useful – a website, or a service, or a mobile app. These all have many moving parts – Authentication so users can log in, database support for storing data, file uploads so users can store their cat pictures in the database – all of these … Read more

Home » Programming » Javascript

The JavaScript Frameworks We’re Using for 2022

Javascript Frameworks

When building a JavaScript application, you don’t need to write everything from scratch. Instead, javaScript frameworks provide the base to build your app. Here are the ones we’re using in 2021 and into 2022. Node.js https://nodejs.org/en/ JavaScript originated as a scripting language for use on web pages – to be executed within a web browser. Node.js breaks JavaScript out of the browser and allows it to run stand-alone. It’s not technically a framework, but you’ll need to know what it is as some frameworks will run … Read more

Home » Programming » Javascript

Check if a JavaScript Variable is an Array with isArray() [Examples]

Javascript Array.isArray()

Here’s a short article that explains arrays and how to check if a JavaScript variable is an array using the Array.isArray() method. Want to check out whether an array contains a value? Find out how here. What is An Array? An array is a type of JavaScript variable that can hold other variables, or references to other variables, in a list at a certain position. Declaring an Array in JavaScript An array is declared in JavaScript the same way as any other variable – by assigning the value … Read more

Home » Programming » Javascript

Checking for null values in JavaScript, With Examples

Javascript Null Check

What is null in JavaScript, and how can you check if a value is equal to null? Read on to find out. What is Null? Null is a term with a special meaning in computing and computer programming. Null is not 0 (zero). Null means that something has no value. Zero is a value (a number). An empty string has a value (though sometimes called a null string, they aren’t null). A variable with a value of null is considered to be empty. It is not undefined – it has been defined … Read more

Home » Programming » Javascript

How to Remove Duplicates From an Array in JavaScript [Examples]

Javascript Remove Duplicates from Array

Being able to remove duplicates from (or de-duplicate) an array is a useful thing to be able to do. Here’s how it’s done. What is an Array? In programming, an array is a type of variable that can hold other values, or references to other variables, in a list at a certain position. Arrays are vital to building any application – allowing you to store a list of variables or values of any length in a single variable – ready to be iterated over, processed, … Read more

Home » Programming » Javascript

JavaScript – Pausing Execution or Sleep Function Equivalent

Javascript Pause/Sleep

JavaScript does not include a sleep function to pause execution – but you can achieve the same effect with this simple code. Unlike shell scripts and PHP, JavaScript does not include a built-in function to pause execution for a set amount of time. In other programming languages, this is usually called the sleep function. Unfortunately, JavaScript doesn’t have an equivalent function, but we can build one ourselves! JavaScript Promises Modern versions of JavaScript include support for new functionality called promises. Put simply; a promise is a new … Read more