You cannot change the value of a key in javascript object. Instead, you can assign a new key and then remove the prior key:
var x = {
"a1": "example1",
"b2": "example2",
"c3": "example3"
};
// assign new key with value of prior key
x["a2"] = x["a1"];
// remove prior key
delete x["a1"];
And, please understand that these are NOT arrays. These are Javascript objects. An array is a different type of data structure.
The syntax for (var key in x) is the usual way to iterate properties of an object. Here's a summary of several different approaches:
// iterate all enumerable properties, including any on the prototype
for (var key in x) {
console.log(key +", " + x[key]);
}
// iterate all enumerable properties, directly on the object (not on the prototype)
for (var key in x) {
if (x.hasOwnProperty(key)) {
console.log(key +", " + x[key]);
}
}
// get an array of the keys and enumerate that
var keys = Object.keys(x);
for (var i = 0; i < keys.length; i++) {
console.log(keys[i] +", " + x[keys[i]]);
}
{"a1": "example1"}syntax is a Javascript object, NOT an array.