Array Flashcards

1
Q

Arrays are what types of data ?

A

they are of type ‘object’ and data type in javascript.

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

How many types of arrays do we have

A

2 types
arrays literals and constructor array

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

how do we set arrays

A

it has to be in a variable and has value s
const number = [12, “hello”, true, false];
[ elements in the square brackets]

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

How do access values in an array?

A

Array are number based this means they start from number 0
const numbers = [12,13,14, 2,15,24,188]
let x;
x = numbers[2]
console.log(x)
we can also use template literals
my favourite number is ${numbers[3]};

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

Methods in arrays
what does method push do ?

A

it adds a value at the end of an existing array
arr.push(100);

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

what does pop do

A

it removes a value from the array at the end.
arr.pop();

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

what does unshift do?

A

it adds a value at the beginning of the array
arr.unshift(99);

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

what does shift do?

A

it removes a value from the beginning of the array
arr.shift()

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

what does reverse do

A

it reverses the values from beginning to the end
arr.reverse();

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

what does includes method do ?

A

this method checks if the array list includes a specific value in the array and return a boolean value true or false, if the value is there its going to return true if not
it will return false.
arr.includes(200);

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

what does indexOf do?

A

it gives you or return the index of a value

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

what does slice do?

A

it will slice the array and return the array in range of the slice
arr.slice(1, 4) “it will return within that range”
and we have the start index to the index you want returned.

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

what does splice do ?

A

it works like slice but it manipulate/change the original array. the first is the start index the second is the elements you want to go over
arr.splice(1, 4);

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

how do we chain methods ?

A

x = arr.splice(1, 4).reverse()toString();

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

What is nesting in Array ?

A

Is having an array as an Index inside of another array

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

examples

A

const fruits = [‘apple’, ‘banana’, ‘orange’];

const berries = [‘strawberries’, ‘blueberry’, ‘raspberry’];
fruits.push(berries);

console.log(fruits)

17
Q

how do we access in a nested array ?

A

let x;

x = fruits[1][1];
console. log(x);

18
Q

How do we concatenate arrays

A

It’s not putting the array inside the array, but it’s taking the items from one array and basically adding them into a different array

x = fruits.concat(berries);

19
Q

what is spread operator

A

spread operator(. . .);
the spread operator, is represented by three dots and this can be used in arrays and objects

x = [. . .fruits, . . .berries];
console.log(x)
NB
‘does the same operations as concat
in an event that you want to take something from 1 and 1 array and spreed those items across inside another array

20
Q

how to flatten an array when this is when you have arrays nested in an array

A

const arr = [1, 2, 3, [4, 5], 6, [7, 8];

x = arr.flat();

21
Q

Static array object

A

one of its use is to check if something is an array

Array.isArray(fruits)

22
Q

static object from

A

This method will create an Array from an array like value.
this is very useful when it comes to HTML collection or node list
x = Array.from (12345)
it will convert string into an Array