Home » Search results for 'javascript array'

JavaScript for Loops – How to Use Them [Examples]

How to use for loops in JavaScript

This article will show you how to use the simplest JavaScript loop – the for loop, and provide code examples. JavaScript for Loops JavaScript’s for loops are used to execute a block of code repeatedly until a condition is met. The initial variables, condition that must be met, and the expression which progresses the loop are all defined within the loop expression. for loop Syntax JavaScript for loops follow the following syntax: for (INITIALIZATION; CONDITION; FINAL_EXPRESSION) { //Code to be executed in the loop } Note that: INITIALIZATION sets the variable which is used to control … Read more

Home » Search results for 'javascript array'

How to Use Nested For Loops in JavaScript, with Examples

JavaScript nested for loops

This article will quickly explain nested for loops in JavaScript, how they are used with multidimensional arrays, and show some examples. For Loops We’ve already covered for loops – check out our article here. To sum up the article, for loops repeat a block of code for a given number of iterations: for (let i = 0; i <= 3; i++) { console.log(i); // Will output the numbers 0-3 to the console } Above, a for loop is defined that defines an initial variable i that is used to control the loop, sets a … Read more

Home » Search results for 'javascript array'

Check/Validate String Matches Regex in JavaScript [Examples]

JavaScript regex match

This article will show you how to use Regular Expressions (Regex) to validate matching strings in JavaScript. All user input collected in your applications should be validated. If an email address is required, a valid email address should be entered, or sending the email will fail. If a phone number is required, a valid phone number must be entered, and so on. Regex can be used for this validation by matching a whole string to a specified format. Regex can also be used to search … Read more

Home » Search results for 'javascript array'

Generate a Hash from String in Javascript, with Examples

JavaScript Hash String

This tutorial will show you a practical way to generate a hash for a string in JavaScript, and provide working code examples you can use in your own project. What is a Hash? A Hash or Checksum is a calculated value with a specific length. By passing a hashing algorithm a string – which can be any length – a calculated hash of a consistent length is returned. Whenever the same string is passed to the hashing algorithm, the same calculated hash should be returned. … Read more

Home » Search results for 'javascript array'

Using the JavaScript toUpperCase() String Method [Examples]

JavaScript toUpperCase()

This article shows how the toUpperCase() method is used in JavaScript to make all letters in a string UPPER CASE. The toUpperCase() method is included in the string object and is fully supported in all browsers. In the JavaScript programming language, strings can either be a primitive or an object – primitives are the most basic kinds of variables – they have no methods, and simply represent the raw data for the given characters. String objects, however, have additional methods for manipulating and measuring the string – the toUpperCase() is one of these helpful methods. String variables in … Read more

Home » Search results for 'javascript array'

How to Create a Countdown Timer in JavaScript

JavaScript Countdown Timer

This tutorial will demonstrate how to create a countdown timer in JavaScript, including a function you can copy and paste into your own code. The below code will break down creating a function which calculates the time until a certain future time, and how to run it repeatedly to affect a count down timer. Getting the time remaining until a certain date/time The below function will calculate the days, hours, minutes, and seconds to a target date: function timeToTarget(countdownString){ // Convert the string which specifies … Read more

Home » Search results for 'javascript array'

Promises in JavaScript: What they Are, How to Use Them

JavaScript Promises

Promises are a feature of JavaScript which allow code to continue executing in the background, and perform an action with the result when it has completed. This article will show you how to use Promises. What is a ‘Promise’ in JavaScript? A Promise is an object in JavaScript which acts as a placeholder for the eventual result of an operation. A Promise is either: Pending while the operation completes Fulfilled when the operation is successful Rejected if the operation fails Promises allow for asynchronous code execution in JavaScript. … Read more

Home » Search results for 'javascript array'

The JavaScript toString() Method, Explained + Examples

JavaScript toString()

One of the most common things you will want to do with a variable is to print a string representation of it. That’s what the toString() method is for. This article will explain when and how you can use it. Converting to Strings Data is displayed on your computer screen is most frequently displayed as text strings, regardless of how the data was stored. Numbers, arrays, boolean values, and objects, all have string representations that allow them to be viewed as text on screen, either for the … Read more

Home » Search results for 'javascript array'

How to use the JavaScript ‘while’ Loop, With Examples

JavaScript While Loops

This article will show you how a JavaScript while loop is constructed, and what it us used for, with code examples. While loops are one of the simplest kinds of loops, and appear in most programming languages. A while loop runs a block of code repeatedly, until a condition is met. When the while condition is met, the loop stops. It’s important to get comfortable with using loops – and understanding how they work – as they form the backbone of just about every game and application you might write. Make sure you’re familiar … Read more

Home » Search results for 'javascript array'

JavaScript Print – To the Console, WebPage, or a Printer [Examples]

JavaScript Print to Printer, Console, Page

You’ve searched for ‘JavaScript Print’ – so you’re probably trying to output data to the console, to the webpage or to a printer. Here’s how to do all three. Printing to the Console with console.log() The JavaScript console.log() method prints data to the JavaScript console (visible in your browsers web inspector). Any type of data can be logged to the console, including strings, numbers, arrays, and objects, and either the contents of, or a text representation of, the value will be displayed. console.log() is frequently used for debugging – developers use it to view … Read more