Alright, I have an array named arrayObj
containing three objects: arrayObj[0]
, arrayObj[1]
, and arrayObj[2]
. All of these objects have the key name["user"]
repeated three times. To change these key names using a function, here's what I've come up with so far:
function renameObjNames(){
arrayObj[0].randomkeyname = arrayObj[0].user;
delete arrayObj[0].user;
}
However, this function only works for the first object. I attempted to use a for-loop to solve this issue but my loop skills are lacking. Is there a way to dynamically change the index in arrayObj[?], so that all three key names can be changed at once within a function?
I would greatly appreciate any additional assistance. Apologies if my grammar is not perfect. Thank you in advance :).