Created
August 5, 2015 12:13
-
-
Save kewogc/670fc4a25b1ecd5bbcd6 to your computer and use it in GitHub Desktop.
Revisions
-
kewogc created this gist
Aug 5, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ _.mixin replaceKey: (obj, key, value) -> _obj = _(obj) _obj.each (v, k) -> if k == key obj[k] = value else if obj[k] == Object(obj[k]) replaceKey obj[k], key, value return _obj # usage # obj = {a: 1 , b: [{a: 2}]} # _.replaceKey(obj, 'a', 3) #obj-> a: 3 , b: [{a: 3}]}