Home » Search results for 'javascript array'

Filter JavaScript Array With Multiple Conditions/Values [Examples]

JavaScript filter array using multiple conditions/values

This article will show you how to filter an array using multiple conditions, to return multiple values. Example code is provided. We’ve already covered filtering arrays in general – this article covers specifically how multiple conditions can be used with the Array.filter() method. The Array.filter() Method The filter() method is available on all arrays in JavaScript. It creates a new array, containing only the items from the original array which passes all conditions in a provided function. filter() Method Syntax The syntax for the array filter() method is as follows: ARRAY.filter(ELEMENT => FUNCTION) Note that: ARRAY is … Read more

Home » Search results for 'javascript array'

Array.shift() to Remove First Item from JavaScript Array [Examples]

JavaScript Array Shift

This short tutorial will show you how to use the JavaScript Array.shift() method to remove items from an array, and provide some code examples. JavaScript Arrays An array is a variable type which can hold zero or more values within it. Each value in an array has a position, called the index – which is an integer value representing the items position in it’s order of appearance. Indexes start counting at position 0 – so the first item in an array is at index 0, the second item at index 1, and so on. JavaScript … Read more

Home » Search results for 'javascript array'

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 array'

How to Get the Last Item in a JavaScript Array [Quick Tip]

JavaScript - Get last item in array

This quick article will show you how to get the last item in an array in the JavaScript programming language. Arrays and Array Indexes in JavaScript Arrays are an ordered list of items. Each item in the array has a numerical index that defines its permission in the array. The first index is index 0 (indexes start counting at 0, not 1!), so the last index is the array’s length; subtract 1. Getting the Last Item in an Array So, to get the last item in an array, we just … Read more

Home » Search results for 'javascript array'

Hash Tables/Associative Arrays in JavaScript – How and Why?

JavaScript Hash Tables

JavaScript does not have a native object class called a “hash table” – but that doesn’t mean that the functionality of hash tables doesn’t exist in the language. Here’s how to use hash tables in JavaScript, with working example code. What is a Hash Table? Also known as hash maps, hash tables are a data structure which maps a list of keys to a list of corresponding values for each key. Any value in the table can be retrieved by accessing it through the associated key. … Read more

Home » Search results for 'javascript array'

Checking an Array Contains a Value in JavaScript [Examples]

JavaScript in array includes

This article will show you how to check if a value is in an array in the JavaScript programming language. Code examples to check whether an array includes a value are provided. Arrays in JavaScript Arrays are a type of variable that hold an ordered list of values. Each value in an array has a position within the array, called the index. The index can be used to access each value in the array. Indexes are integer values, which start counting from 0 (zero) for the first … Read more

Home » Search results for 'javascript array'

How to Convert Array to String in JavaScript with toString() and join()

JavaScript Array to String

This brief tutorial will show you two ways to convert JavaScript arrays to strings using the toString() and join() methods. What Are Arrays? An array is a data structure which holds multiple values. It’s like a numbered list – each item in the array has a value and a position (called the index). The indexes start counting at position 0, so the first item in an array is at index 0, the second at index 1 and so on. Converting Arrays to Strings in JavaScript There are many reasons you may wish … Read more

Home » Search results for 'javascript array'

How to Sort Arrays in JavaScript with the sort() Method [Examples]

Javascript Sort Array

This tutorial will show you how to sort arrays in the JavaScript programming language with the array sort() method and provide some code examples. What is an Array in JavaScript? An array is a type of JavaScript variable that can hold a series of variables, references to variables, or values. It’s like a list of items. Each item or element in the array has a value and a position. The position is the order the element appears in the array and is called the index. Indexes are zero-indexed – meaning … Read more

Home » Search results for 'javascript array'

Copy/Clone an Array or Object in JavaScript The Right Way [Examples]

How to Copy/Clone JavaScript Array

This tutorial will show you how to properly copy/clone an array or object in JavaScript – it’s not as simple as it seems! Copying an array or object may seem simple – but JavaScript throws a spanner in the works – the fact that when you assign the value of one variable to another it references the original variable. This means that if the value of the original variable is changed, the value of the copy will change too! To get around this, you will need to clone the array – ensuring … Read more

Home » Search results for 'javascript array'

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