函数应该返回一个对象,该对象的键为参数someKey,值为someValue

时间:2019-07-09 17:39:15

标签: typescript

该函数应返回一个 单个对象  以键为参数 someKey和value作为someValue

let convertToKeyValuePair = (someKey,someValue)=>{

    return { someKey : someValue}

    // this function should return a single object which has      
    //key as the value of someKey and value as someValue
};

console.log(convertToKeyValuePair("someKey","someValue"))

let convertToKeyValuePair = (someKey,someValue)=>{

   // this function should return a single object which has      
   //key as the value of someKey and value as someValue

};



module.exports = {convertToKeyValuePair:convertToKeyValuePair};

1 个答案:

答案 0 :(得分:1)

我假设您要使用computed property name?在变量周围添加方括号:

let convertToKeyValuePair = (someKey,someValue)=>{

    return { [someKey] : someValue}

    // this function should return a single object which has      
    //key as the value of someKey and value as someValue
};
相关问题