Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
1. `.sort()`
* Use the `sort` method to put the array `carsInReverse` into alphabetical order.
* Based on the types of cars you used, predict which item in the array should be at index 0.
* Use the following code to confirm or reject your prediction: `console.log(carsInReverse.indexOf('yourPrediction'));`
* Use the following code to confirm or reject your prediction: `carsInReverse`
1. `.slice()`
* Create a `pets` array by copy/pasting the following: `const pets = ['dog', 'cat', 'fish', 'rabbit', 'snake', 'lizard', 'bird']`
* Use the `slice` method to create a `reptiles` array with `snake` and `lizard` from the `pets` array.
Expand Down
97 changes: 97 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// ***********console.log()**********************

const cars = ["Ford", "Range Rover", "Mclaren", "Mercedes"];
console.log(cars.length);

const moreCars =["lambo", "tesla", "chevy", "honda"];
console.log(moreCars.length);

// ***********Concat()**********************

console.log(cars.concat(moreCars));

const totalCars = cars.concat(moreCars);

console.log(totalCars.length);

// ***********indexOf()**********************

console.log(totalCars.indexOf("honda"));

// ***********lastIndexOf()**********************

console.log(totalCars.lastIndexOf("Ford"));

// ***********join()**********************

const stringOfCars = totalCars.join()

console.log(stringOfCars);

// ***********Split()**********************

const carsFromString = stringOfCars.split()

console.log(carsFromString);

// ***********reverse**********************

const carsInReverse = totalCars.reverse();

console.log(carsInReverse);

// ***********Slice()**********************


const pets = ['dog', 'cat', 'fish', 'rabbit', 'snake', 'lizard', 'bird']

const reptiles = pets.slice(4,6);

console.log(reptiles);

console.log(pets);

// ***********Splice()**********************

const removedReptiles = pets.splice(4, 2, 'hamster');

removedReptiles

console.log(pets)


//***********pop()**********************

const removedPet = pets.pop()

console.log(removedPet)

console.log(pets)

//***********push()**********************

pets.push(removedPet)

console.log(pets)


//***********Shift()**********************

console.log(pets.shift([0]));


//***********unshift()**********************

pets.unshift('turtle',);

console.log(pets)

//***********forEach()**********************

const numbers = [23, 45, 0 , 2, 8, 44, 100, 1, 3, 91, 34];

numbers.forEach(num => {
console.log(num + 2)
})

console.log(numbers)