javascript-arrays Flashcards
What are arrays used for?
Arrays are used to store and manage collections of data, such as lists of items or values. In JavaScript, arrays are objects that can be used to store multiple values in a single variable.
Describe array literal notation.
enclosing a comma-separated list of values in square brackets and assigning that to a variable
How are arrays different from “plain” objects?
Arrays and plain objects are two different data types in JavaScript. An array is an ordered collection of values, while a plain object is an unordered collection of key-value pairs.
One of the main differences between arrays and plain objects is that arrays have a set of built-in methods for manipulating the data they contain
Another difference is that arrays are ordered, which means that the elements in an array have a specific position or index, starting from 0. This allows you to access or modify specific elements in the array using their index. In contrast, plain objects are unordered, which means that the elements in the object do not have a specific order or position.
What number represents the first index of an array?
0
What is the length property of an array?
The length property of an array is a read-only property that returns the number of elements in the array. In JavaScript, you can use the length property to find the size of an array
How do you calculate the last index of an array?
To calculate the last index of an array in JavaScript, you can use the length property of the array and subtract 1 from it. This is because the index of an array starts at 0, so the last element in the array will have an index that is one less than the length of the array.