javascript:将相同和不同的键映射到不同的值

时间:2019-02-15 14:53:45

标签: javascript

var dict = {
'thunder':    'severe thunderstorms',
     'sun':    'thunderstorms',
     'moon':    'mixed rain and snow',
 'Rain':    'severe thunderstorms',
     'Rain':    'thunderstorms',
     'Rain':    'mixed rain and snow',
     'Rain':    'mixed rain and sleet',
}
var result = String(state.cell.value.key);

/*How do I get 
     sun
   /     \
thunder weather
           \
           rain
              |- 'severe thunderstorms'
              |- 'thunderstorms'
              |- 'mixed rain and snow'
              |- 'mixed rain and sleet'*/

1 个答案:

答案 0 :(得分:1)

只需使用array

var dict = {
    thunder: 'severe thunderstorms',
    sun: 'thunderstorms',
    moon: 'mixed rain and snow',
    rain: ['severe thunderstorms',
        'thunderstorms',
        'mixed rain and snow',
        'mixed rain and sleet']
}
console.log(dict)