Home » Programming » Javascript

Exiting JavaScript Loops: ‘break’ & ‘continue’ [Examples]

Javascript Break Continue Statements

This article will explain the JavaScript break and continue statements and how they are used to exit and skip iterations in loops. JavaScript Loops In programming, a loop iterates through a series of values, performing an action on each value it encounters. Arrays can be looped through using the forEach method, and the for statement can be used to loop through a set of values generated by a JavaScript expression. You may encounter situations where you want to prematurely exit a loop, or skip processing certain values in the loop. This is what … Read more

Home » Programming » Javascript

Searching JavaScript Arrays with the Array.find() Method [Examples]

Javascript Array find()

This tutorial will show you how to search arrays in JavaScript using the Array.find() method, and show some code examples. JavaScript Arrays An array is a type of variable that holds an ordered list of values (or references to other variables), called array elements. Each element has a position in the array, called the index – and can be accessed by using that index. We’ve got a whole pile of things you can do with JavaScript arrays. Accessing elements in the array by their index is convenient, … Read more

Home » Programming » Javascript

Multidimensional/Nested Arrays in JavaScript [Guide]

Multidimensional/Nested Arrays in JavaScript

This guide aims to succinctly show you how multidimensional arrays can be created and used in the JavaScript programming language. What are Arrays? Arrays are a key component in any app kind of app you may wish to build – arrays allow you to store an ordered list of variables or values of any length in a single variable – ready to be iterated over, displayed, or otherwise processed. For example, an array could contain a list of contacts for an instant messaging application, or … Read more

Home » Programming » Javascript

JavaScript vs Python – Which Should I Learn in 2022?

JavaScript Vs Python

If you’re looking to learn how to program, Python and JavaScript are obvious choices – but which one would be most useful to you? Python and JavaScript are probably the most popular programming languages at the moment, and both have a lot of tutorials to follow. If you don’t have a specific task or problem you wish to solve, it can be difficult to decide which programming language to learn. While the fundamentals are the same regardless of language, the applications are different. Fortunately, JavaScript … Read more

Home » Programming » Javascript

JavaScript: Compare Strings (Optionally Ignoring Case), With Examples

JavaScript Compare Strings

This quick tutorial will show you how to compare two or more strings in the JavaScript programming language – optionally ignoring case – with code examples. What are Strings? Strings are a series of characters. Each character has an ordered position in the string. A string can be of any length – from 0 (zero) characters to as many as you need until your computer runs out of memory. Strings are a type of variable. String type variables in JavaScript are variables that can hold a string … Read more

Home » Programming » Javascript

Why Using the Right Variable Type is Important (Especially in Javascript)

Programming Variable Types

Variable types are a fundamental programming concept that often confuses beginners – especially those learning JavaScript. This article will show you the consequences of using the wrong variable types. What is a Variable Type? In computer programming, the type of a variable determines what values a variable can hold and what can be done with the variable. As an example, numeric variables can have mathematical operations performed on them, whereas string variables cannot (more on this later). Different programming languages support different types of variables, … Read more

Home » Programming » Javascript

How to Convert an Object to an Array in JavaScript [Examples]

JavaScript Convert Object to Array

This article will show you the ways to convert an object to an array in JavaScript – quickly and easily. There are many ways to convert objects to arrays, but these (should) be the most straightforward methods. Converting Object to Array in JavaScript – Values Only If you only need the values from the object, the Object.values() method will extract them into an array: var myObject = { colour: ‘blue’, number: 43, name: ‘Fred’, enabled: true }; var values = Object.values(myObject); console.log(values); The above will return an array with … Read more

Home » Programming » Javascript

Converting Object to an Array Recursively in JavaScript

JavaScript Recursive Object to Array

The Object.entries() method in JavaScript can be used to convert an object to an array – but it doesn’t work recursively. So here’s a function to accomplish that. I can’t think of a reason why you’d want to do this, but it came up while putting together an article on using Object.entries() – so here it is! Recursive Function for Converting Objects to Arrays I’ll let the comments do the talking as to what’s going on. The gist of it is that (for whatever reason) you want to convert an … Read more

Home » Programming » Javascript

JavaScript: Remove the First/Last Character from a String [Examples]

How to Remove First/Last Characters from String in JavaScript

This tutorial will explain a few ways to remove the first or last character (or both!) from a string in the JavaScript programming language. This can be useful if you need to capitalize names or sentences or remove punctuation. Remove First/Last Character Using The substring() Method The JavaScript substring() method can be used to remove the first or last character from a string. You can find out more about the substring() and similar substr() methods here. The below code example shows how to remove the first, last, and both the first … Read more

Home » Programming » Javascript

JavaScript substr() and substring() – What’s the Difference?

JavaScript substring/substr Difference

JavaScript has two similar-looking methods for extracting substrings from strings – substr() and substring(). This article explains the difference. These two functions perform almost the same function and have almost the same name, and at a glance, even seem to have the same syntax – but they’re different! Here is the syntax for each function – side by side so that you can see the difference. A Quick Reminder about Indexes An index is the integer number representing the position of an item in a series. Indexes start counting at 0 – so the … Read more