Conditionally set an object property

后端 未结 6 1981
太阳男子
太阳男子 2020-12-04 17:37

Is there some syntax for setting properties based on a condition?

data: {
    userId: 7,
    actionId: 36,
    express: (myCondition ? true : null) // does n         


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 18:08

    You could do something like this:

    var json = JSON.stringify( {
        data: {
            userId: 7,
            actionId: 36,
            express: (myCondition ? true : null)
        }
    });
    

提交回复
热议问题