Pilcrow Records

Scripter Javascript Tutorial

javascriptmusiclogicscripterbookexcerpttutorial

51 Update data in an object

To update the data already in the object, the same notation to get data can be used to update. Using the key index number is rare.

var scale = {
		"name" : "C Major",
		"pitches" : [60, 62, 64, 65, 67, 69, 71]
	};
	
scale.name = "C Ionian"; // was "C Major"
scale["pitches"] = []; // replaced the populated array with an empty one
scale[1] = [0, 2, 4, 5, 7, 9, 11]; // replaced the empty array with a populated one