I have an array of objects :
arrayOfObject = [{'key1': [1,2]} , {'key2': [1,2,3]} , {'key3': [1,2,4]}]
I have the name of the key I want to replace in my array :
var keyString = 'key1';
And I have the new name the key should take :
var newKey = 'newKey'
How to make my array this :
arrayOfObject = [{'newKey': [1,2]} , {'key2': [1,2,3]} , {'key3': [1,2,4]}]
JavaScript: Object Rename Key this can help me to rename the key but the thing is how to access the object first in my array that has the key1
key.
Note that keyString
is random. So it's pointless to get it like arrayOfObject[0]