Can I write an if statement within a Javascript object when setting an attribute?

前端 未结 5 1061
自闭症患者
自闭症患者 2021-01-03 23:30

Setting attributeTwo using an if statement. What is the correct way to do this?

var testBoolean = true;

var object = {
  attributeOne: \"attributeOne\",
  a         


        
5条回答
  •  忘掉有多难
    2021-01-04 00:07

    Indeed you can but why don't you do the conditional statement before assigning it to object attribute. The code would be nicer.

提交回复
热议问题