chaesthetics / FrontEnd-Dev

For Meta Certification
0 stars 0 forks source link

Using Spread and Rest #38

Open chaesthetics opened 10 months ago

chaesthetics commented 10 months ago
const fruits = ['apple', 'pear', 'plum']
const berries = ['blueberry', 'strawberry']
const fruitsAndBerries = [...fruits, ...berries] // concatenate
console.log(fruitsAndBerries); // outputs a single array

['apple', 'pear', 'plum', 'blueberry', 'strawberry']

chaesthetics commented 10 months ago

const flying = { wings: 2 } const car = { wheels: 4 } const flyingCar = {...flying, ...car} console.log(flyingCar) // {wings: 2, wheels: 4}

chaesthetics commented 10 months ago
let veggies = ['onion', 'parsley'];
veggies = [...veggies, 'carrot', 'beetroot'];
console.log(veggies);

['onion', 'parsley', 'carrot', 'beetroot']

chaesthetics commented 10 months ago
const greeting = "Hello";
const arrayOfChars = [...greeting];
console.log(arrayOfChars); //  ['H', 'e', 'l', 'l', 'o']
chaesthetics commented 10 months ago
const car1 = {
    speed: 200,
    color: 'yellow'
}
const car 2 = {...car1}

car1.speed = 201

console.log(car1.speed, car2.speed)
chaesthetics commented 10 months ago
const fruits1 = ['apples', 'pears']
const fruits2 = [...fruits1]
fruits1.pop()
console.log(fruits1, "not", fruits2)

['apples'] 'not' ['apples','pears']