Swap key with value JSON

后端 未结 18 2455
花落未央
花落未央 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-30 00:21

    you can use lodash function _.invert it also can use multivlaue

     var object = { 'a': 1, 'b': 2, 'c': 1 };
    
      _.invert(object);
      // => { '1': 'c', '2': 'b' }
    
      // with `multiValue`
      _.invert(object, true);
      // => { '1': ['a', 'c'], '2': ['b'] }
    

提交回复
热议问题