Swap key with value JSON

后端 未结 18 2464
花落未央
花落未央 2020-11-29 23:54

I have an extremely large JSON object structured like this:

{A : 1, B : 2, C : 3, D : 4}

I need a function that can swap the values with

18条回答
  •  隐瞒了意图╮
    2020-11-29 23:56

    I believe it's better to do this task by using an npm module, like invert-kv.

    invert-kv: Invert the key/value of an object. Example: {foo: 'bar'} → {bar: 'foo'}

    https://www.npmjs.com/package/invert-kv

    const invertKv = require('invert-kv');
    
    invertKv({foo: 'bar', unicorn: 'rainbow'});
    //=> {bar: 'foo', rainbow: 'unicorn'}
    

提交回复
热议问题