Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var arrayOfObject = [{'key1': [1,2]} , {'key2': [1,2,3]} , {'key3': [1,2,4]}];
var keyString = 'key1';
var newKey    = 'newKey';
var newArray = arrayOfObject.map(function(item) {
  if (keyString in item) {
    var mem = item[keyString];
    delete item[keyString];
    item[newKey] = mem;
  }
  return item;
});
console.log(arrayOfObject);
console.log(newArray);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers