Home » Search results for 'javascript object'

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 » Search results for 'javascript object'

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 » Search results for 'javascript object'

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 » Search results for 'javascript object'

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 » Search results for 'javascript object'

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

Home » Search results for 'javascript object'

Calculating the Absolute Value in JavaScript with Math.abs()

JavaScript Absolute Value abs()

This article will explain what absolute values are, how they are used, and how the JavaScript Math.abs() function can be used to calculate the absolute value of a number. What is the ‘Absolute Value’ of a Number? The absolute value of a number is that number’s value – without any regard to its sign. A numbers sign determines whether it is positive or negative – it’s the – symbol before a negative number. So, the absolute value of a number is never negative. Consider the absolute value of a number that numbers distance from 0. The absolute value of … Read more

Home » Search results for 'javascript object'

Capitalize the First Letter of Each Word in a String [JavaScript]

JavaScript Capitalize First Letter

This short article shows you how to capitalize the first letter in a string or all of the words in a string (title case) in the javascript programming language. Capitalizing the first letter in a string is useful if you’re capitalizing a single word or a whole sentence which you wish to display in a grammatically correct manner. Converting a string to title case – that’s where every word is capitalized in a string with multiple words – is useful for formatting text for use in an article … Read more

Home » Search results for 'javascript object'

How to Check if an Array is Empty in JavaScript [Examples]

Check if JavaScript Array is Empty

This quick tutorial will show you how to check whether an array is empty in the JavaScript programming language. What is an Array? An array is a type of variable that holds a collection of zero or more values. In JavaScript, arrays are ordered – each value in the array has a position (called the index) in the array, which is used to access it. Indexes start counting at 0, so the first value in an array is at index 0. Declaring an Array in JavaScript The quickest way to … Read more

Home » Search results for 'javascript object'

How to Reset/Clear/Empty an Array in JavaScript

Reset/Clear Array JavaScript

This quick article will show you the right way to reset/clear/empty an array in the JavaScript programming language. The Right Way to Reset/Clear/Empty an Array – Set the length to 0 This is the best way to reset/clear/empty an array in JavaScript. It is unambiguous and will affect both the variable containing the array and any variables referencing the array. var myArray = [1, 2, 3, 4]; myArray.length = 0; Above, an array is declared and then emptied by setting the array’s length property to 0. The Wrong Way – Re-declare the … Read more

Home » Search results for 'javascript object'

How to Read a Local/Remote JSON File in JavaScript [Examples]

JavaScript Read JSON File

This article will show you how to read a JSON file into JavaScript as a JSON object – both local and remote files. What is JSON? JSON (JavaScript Object Notation) is a file format that stores objects, and arrays of objects, as human-readable text. It’s become the most popular method of storing and transmitting structured data on the internet. Thousands of APIs (used for mapping, communication, authentication, and many other purposes) use it as the format for submitting and receiving data. Desktop applications also use it to … Read more