chaesthetics / FrontEnd-Dev

For Meta Certification
0 stars 0 forks source link

Using Spread and Rest #38

Open chaesthetics opened 1 year ago

chaesthetics commented 1 year 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 1 year ago

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

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

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

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

car1.speed = 201

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

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