Skip to content

Instantly share code, notes, and snippets.

@ohcrider
Last active December 19, 2018 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohcrider/8c1d991807c24a67540e7c5e0a361327 to your computer and use it in GitHub Desktop.
Save ohcrider/8c1d991807c24a67540e7c5e0a361327 to your computer and use it in GitHub Desktop.
三目运算符避免不正确的数据
var data = {
a: {
b: ''
},
d: '0',
dct: {
'0': 'aaaa',
'1': 'bbbb'
}
}
var b = data.a? data.a.b: '';
var dFormat = data.dct? data.dct[data.d]: '';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment