How to Use the object of ES6 to clear the object value

Use the ES6 Object to clear the Object value
ES6 Object using incidentally paste JS if clearing the Object value method

In front in the process of compiling, Vue, for example, a page is bounced, bounced in assignment objects, so when we close the popup window after the assignment, the object has not been reset or empty, when open again, bounced objects in the content still exists, according to the normal js method, we will put the value of the object a reduction, this is very troublesome, of course, also may be alone to write a function, but the emergence of ES6 makes the process easier.

ES6 Object is used

# Initializing objects
let param = {
	id: '',
	name: '',
	age: 0,
	isManager: false,
	updateTime: new Date()
}
# Assign a value to an object, not shown here (on-page action).
# Use the Object.keys() function to initialize the object to its original state
```javascript
Object.keys(param).forEach(key => (
	switch (typeof param[key]) {
		case 'string':
			param[key] = '';
		case 'boolean':
			param[key] = false;
		case 'date':
			param[key] = new Date();
		case 'number':
			param[key] = 0;			
	}
))
# Use the above method when special types require special handling.
Object.keys(param).forEach(key => param[key] = '')

By the way, paste js if clearing theobject value method

# Assigned Objects
let param = {
	id: '1',
	name: '2',
	age: 3,
	isManager: true,
	updateTime: new Date()
}
# Start Emptying
for (let key in param) {
	param[key] = ''
}
# The logic of the specific initialization type is the same as that of ES6 above, so I won't repeat it.

Read More: