0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

react/javascript 삼항연산자

Posted at

#조건문과 삼항연산자


  const todos = [
    {
      id:1,
      할일:'소희 한글 프린트하기',
      done:true
    },
    {
      id:2,
      할일:'메모하기',
      done:false
    }
  ];

  const filtered = todos.filter(todo => todo.id !==2);

  const toggled = todos.map(todo => todo.id == 2?{
    ...todo,
    done:!todo.done
  }:todo);

정말 무슨뜻인지 몰라서 고민했다.

const filterd 는 알겠는데
const toggled 의 뜻을 몰라 한참동안을 생각했다.
위 toggled 는
첫째 todos 가지고 맵을 이용해서 조건을 돌린다.
둘째 todo.id ==2 와 같다면 출력 그리고 done 을 반대로 설정하고 출력하라는 뜻
그리고 그외 는 그대로

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?