【问题标题】:change text in object to new key typescript将对象中的文本更改为新键打字稿
【发布时间】:2021-09-21 07:28:51
【问题描述】:

我有一个里面有对象的数组:

export const noteArr = [
  {row1: "test1", row2: "Theme: rowTheme \n" + "/row/details?id=rowId"},
];

然后我有对象 noteParams,我从我的帖子请求中获得

 for(const key of Object.keys(noteParams)){

      console.log(noteParams)// Object { rowTheme: "asd", rowId: "3768" }
      console.log(key)//rowTheme
                      //rowId
                      
       console.log(noteParams[key]) //asd
                                   // 3768
     
    }

我如何将对象 "rowTheme""rowId" 中的 noteArr 更改为来自 noteParams 的值

我需要这样的东西

{row1: "test1", row2: "Theme: asd \n" + "/row/details?id=3768"}

【问题讨论】:

    标签: angular typescript object key


    【解决方案1】:

    这样的???

      const noteArr = [
        { row1: 'test1', row2: 'Theme: rowTheme \n' + '/row/details?id=rowId' },
      ];
    
      const noteParams = { rowTheme: 'asd', rowId: '3768' };
    
      const newValue = noteArr.map((x) => {
        return {
          ...x,
          row2: `Theme: ${noteParams.rowTheme} \n /row/details?id=${noteParams.rowId}`,
        };
      });
    
      console.log(newValue);

    【讨论】:

      猜你喜欢
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      • 2019-01-13
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      相关资源
      最近更新 更多