Array Flashcards
Arrays are what types of data ?
they are of type ‘object’ and data type in javascript.
How many types of arrays do we have
2 types
arrays literals and constructor array
how do we set arrays
it has to be in a variable and has value s
const number = [12, “hello”, true, false];
[ elements in the square brackets]
How do access values in an array?
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]}
;
Methods in arrays
what does method push do ?
it adds a value at the end of an existing array
arr.push(100);
what does pop do
it removes a value from the array at the end.
arr.pop();
what does unshift do?
it adds a value at the beginning of the array
arr.unshift(99);
what does shift do?
it removes a value from the beginning of the array
arr.shift()
what does reverse do
it reverses the values from beginning to the end
arr.reverse();
what does includes method do ?
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);
what does indexOf do?
it gives you or return the index of a value
what does slice do?
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.
what does splice do ?
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 do we chain methods ?
x = arr.splice(1, 4).reverse()toString();
What is nesting in Array ?
Is having an array as an Index inside of another array