So if the value of a key is an array, can I change the value to something else, like a string or an integer?


#1

Question

So if the value of a key is an array, can I change the value to something else, like a string or an integer?

Answer

Yes! Through dot or bracket notation, you can change the value of a key to anything you want:

	let dog = {
						name: ‘Max’,
	breed: ‘Chihuahua’,
	toys: [‘tennis ball’, ‘frisbee’, ‘bone’]
				
};
	
					console.log(dog.toys); // output: [‘tennis ball’, ‘frisbee’, ‘bone’]
	
		dog.toys = ‘rubber duck’;
	console.log(dog.toys); // output: ‘rubber duck’

				
dog[‘toys’] = 10;
					console.log(dog[‘toys’]); // output: 10