Say i have the following object:
obj1 = {
'patato la blaza' : {
'weight' : 5,
'height' : 90
},
'apple ibiza' : {
'weight' : 3,
'height' : 84
}
}
I would like to run through the keys
and modify them, I.E. change the key
values, how do i go about doing this in javascript/jQuery ? , i know i can modify the value
like so:
$.each(obj1 , function(i , e){
obj1[i] = "someramdomvalue"
});
But i don't quite understand how would i go about change/manipulating the values of the keys, in the object provided above i would like to change the value of patato la blaza
to just patato
and apple ibiza
to apple
, i will use a regex to get the shortened version , but i don't know how to add these shortened values as the new key
in the object. would appreciate any help.
NOTE::- i have searched SO already but most of the questions pertain to how to change the value of the value
ob an object and not the keys