Arrays Flashcards

1
Q

Array

A

• stores a list of variables
2 ways to declare them
Var array = […, ….];
var num = new array(….,….); //uncommon way to declare.
• you can have various types within an array.

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

Element

A

• Each item inside an array

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

Array Index

A

• Position number of an element inside an array

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

embedded array

A

• An array within an array
• use “arrayName[2][0];
this example calls the index position of the embedded/inner array and the zero element within the index.

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

.length

A
  • a property that tells you how many elements there are in an array.
  • the last index in an array is always the same number as the length of the array minus 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

xxxx.push();

A

• adds element to the END of an array.

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

xxxx.pop()

A

• removes an element from the END Of an array.

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

xxxx.shift();

A

• removes an element from the beginning of an array

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

xxxx.unshift(“item1”, “item2);

A

• Adds 2 elements to the beginning of an array.

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

xxxx.splice(2, 2, “item1”);

A
  • insert items and or delete items to an array.
  • 1st number is index position where you want to start.
  • 2nd number, number of elements to remove, starting with the first element that comes the element(s) that you’re splicing in.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

xxxx.slice(2, 4);

A
  • copy one or more consecutive elements into a new array.
  • 1st digit index of 1st element to be copied.
  • 2nd digit is the index of the element after the last element to be copied.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

concat

A

• combine arrays together
• firstArray.concat(otherArray) will combine the elements in both arrays.
• To combine multiple arrays put the extra arrays inside the parentheses.
firstArray.concat(otherArray, moreArrays);
e.g.
var items = [1, 2];
var newItems = items.concat(3);

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

xxxx.indexOf(“element”);

A
  • takes an element and returns the FIRST index number where it can be found.
  • multiple occurrences it will list the first one.
  • returns -1 if not found.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
xxxx.forEach(function(element) {
// statement 
});
A
  • JavaScript built in method of iterating through a for loop.
  • Allows you to iterate an array faster instead of using a for loop.
  • array.forEach(someFunction)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly