Assigning a substitute value in case of nil

前端 未结 3 1089
别那么骄傲
别那么骄傲 2021-01-13 15:13

I have a few variables:

name
age
address
phone
social_security
email
weight

And an array called personal_details with each of

3条回答
  •  余生分开走
    2021-01-13 15:49

    You could do this since a nil value returns false and || will only evaluate the right-hand side if the left-hand side is false:

    name = personal_details[0] || ''
    

提交回复
热议问题