How can I convert a TypeScript object to a plain object?

后端 未结 3 1503
故里飘歌
故里飘歌 2021-02-18 21:59

I\'m using a JS library, specifically select2 that acts a tad differently than I\'d like if the objects I\'m passing it aren\'t plain objects. This is all checked b

3条回答
  •  灰色年华
    2021-02-18 22:04

    Something like this is simple and it works :

    let plainObj;
    try {
        plainObj = JSON.parse(JSON.stringify(obj));
    } catch(e) {
        console.error(e)
    }
    

提交回复
热议问题