Rest and Spread (2)

Jang Byeong Mok·2020년 2월 9일
0

Javascript

목록 보기
6/9

JS Rest and Spread (2)

<script>
  const user = {
    name: "mango",
    age: 1234,
    password: 455
  };
  const killAge = ({ age, ...rest }) => rest;
  const cleanUser = killAge(user);
  console.log(cleanUser); //output {name:"mango", password:455}

  const car = {
    name: "k5",
    cc: 2400,
    price: 3000
  };
  const setCountry = ({ country = "KR", ...rest }) => ({
    country,
    ...rest
  });

  console.log(setCountry(car)); //output : {country:"KR" name: "k5", cc: 2400, price: 3000}

  const food = {
    name: "mango",
    price: 500
  };

  const rename = ({ name: Fruit, ...rest }) => ({ Fruit, ...rest });
  console.log(rename(food)); //output : {Fruit:"mango", price:500}
</script>

0개의 댓글