I am trying to update JSON based on user input.
I have an existing JSON array:
colorDataInitial = {
"ML1TEST1" : "#120101",
"ML1TEST2" : "#120101",
"ML1TEST3" : "#120101",
"ML1TEST4" : "#120101",
"ML1TEST5" : "#120101",
}
And want to update one of these to a new color based on user input:
var roomID = $('#room').val();
But when I attempt to loop through this the dot notation only adds as a new key:
var arrayLength = roomArray.length;
for (var i = 0; i < arrayLength; i++) {
if (roomArray[i] == roomID) {
var colorDataTest.roomID = "#FF1C1C"
} else {
var colorDataTest.roomID = ("ML1TEST" + i);
}
}
Output:
ML1TEST1: "#120101"ML1TEST2: "#120101"ML1TEST3: "#120101"ML1TEST4: "#120101"ML1TEST5: "#120101"roomID: "#FF1C1C"
How would I get it to accept the string as the user input?
Thanks for any help