Is there any way to rename js object keys using underscore.js

后端 未结 13 1834
小蘑菇
小蘑菇 2020-12-05 01:21

I need to convert a js object to another object for passing onto a server post where the names of the keys differ for example

var a = {
    name : \"Foo\",
          


        
13条回答
  •  猫巷女王i
    2020-12-05 02:06

    As far as I know there is no function built into either of these two libraries. You can make your own fairly easily, though: http://jsfiddle.net/T9Lnr/1/.

    var b = {};
    
    _.each(a, function(value, key) {
        key = map[key] || key;
        b[key] = value;
    });
    

提交回复
热议问题