javascript-arrays Flashcards

1
Q

What are arrays used for?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe array literal notation.

A

enclosing a comma-separated list of values in square brackets and assigning that to a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are arrays different from “plain” objects?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What number represents the first index of an array?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the length property of an array?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you calculate the last index of an array?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly