简体   繁体   English

用它的值替换键名

[英]Replace key name by its value

 todo = {
"1.CoverLetterPage":"Hello",
    "3.JoiningDate":"Any Day",
    '4.Location':'Texas',
    '6.Leave':'AnyDay',
 };

I have called the list of keys in the list我已经调用了列表中的键列表

done=[1.CoverLetterPage,4.Location,"3.JoiningDate,6.Leave]

What if i want to replace the values in the list 'done' by its value by typescript如果我想用 typescript 的值替换列表“完成”中的值怎么办

Use map function to obtain values from todo object and overwrite done .使用 map function 从todo object 获取值并覆盖done

this.done = this.done.map( v => this.todo[v] )

Also your done array values should be in string form with qoutes around them like below:此外,您完成的数组值应该是字符串形式,周围有 qoutes,如下所示:

done=['1.CoverLetterPage','4.Location','3.JoiningDate','6.Leave']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM