title: Transform all keys in array from underscore to camel case in js
body: <p>So, I need to transform all keys in array from underscore to camel space in js. That is what I need to do before send form to server. I'm using <code>Angular.js</code> and I want to represent it as a filter (but I think it's not rly important in this case). Anyway, here is a function I've created.</p>
  
  <pre><code>.filter('underscoreToCamelKeys', function () {
          return function (data) {
  
              var tmp = [];
              function keyReverse(array) {
                  angular.forEach(array, function (value, key) {
                          tmp[value] = underscoreToCamelcase(key);
                  });
  
                  return tmp;
              }
  
              var new_obj = {};
              for (var prop in keyReverse(data)) {
                  if(tmp.hasOwnProperty(prop)) {
                      new_obj[tmp[prop]] = prop;
                  }
              }
              return new_obj;
          };
  
          function underscoreToCamelcase (string) {
              return string.replace(/(\_\w)/g, function(m){
                  return m[1].toUpperCase();
              });
          }
      })
  </code></pre>
  
  <p>Here I will try to explain how it works, because it looks terrible at first.</p>
  
  <p><code>underscoreToCamelcase</code> function just reverting any string in underscore to came case, except first character (like this <code>some_string =&gt; someString</code>)</p>
  
  <p>So, as I said earlier, I should revert all keys to camel case, but as you understant we can't simply write </p>
  
  <pre><code>date[key] = underscoreToCamelcase(key)
  </code></pre>
  
  <p>so <code>keyReverse</code> function returns a reverted array, here is example</p>
  
  <p><code>some_key</code> => <code>value</code></p>
  
  <p>will be</p>
  
  <p><code>value</code> => <code>someKey</code></p>
  
  <p>and for the last I simply reverting keys and values back, to get this</p>
  
  <p><code>someKey</code> => <code>value</code></p>
  
  <p>But, as you already may understand, I got a problem, if in array exists the same values, those data will be dissapear</p>
  
  <p>array</p>
  
  <p><code>some_key1</code> => <code>value</code>,
  <code>some_key2</code> => <code>value</code></p>
  
  <p>returns as</p>
  
  <p><code>someKey2</code> => <code>value</code></p>
  
  <p>So how can I fix that? I have a suggestion to check if those value exists and if it is add some special substring, like this</p>
  
  <p><code>some_key1</code> => <code>value</code>,
  <code>some_key2</code> => <code>value</code></p>
  
  <p><code>value</code> => <code>someKey1</code>,
  <code>zx99value</code> => <code>someKey2</code></p>
  
  <p>and after all parse it for zx99, but it I think I`m going crazy...
  Maybe some one have a better solution in this case?</p>
  
  <p>Important! Them main problem is not just to transform some string to camel  case, but do it with array keys!</p>