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:
- The background object of thymeleaf is null, which solves the problem of error when the object is empty to get the property value
- Ubuntu: Failed to initialize compiler: object java.lang.Object In compiler mirror not found
- nvalid default value for prop “params“: Props with type Object/Array must use a factory function to
- The JSON object is converted into a formdata object, and the formdata object is converted into a JSON object
- how to clear screen in python shell
- Object is JSON, and JSON is converted to object
- Error: invalid permission for adding an object to repository database
- Trivia: How does R language solve Error in ts(x):’ts’ object must have one or more observations
- JavaScript summary: the difference between typeof and instanceof, and Object.prototype.toString() method
- [Solved] VUE-pdf Plugin use error: To install them, you can run: npm install –save core-js/modules/es
- 【ERROR_2】Call to a member function bind_param() on a non-object
- Fatal error: Call to a member function bind_param() on a non-object in
- Abnormal display of page object moved to here
- [Qt] error: call to non-static member function without an object argument
- Solutions to Excel 2007 “cannot shift object off sheet”
- Failed to start Ceph object storage daemon osd.14
- Call to a member function fetch_assoc() on a non-object
- PHP Fatal error: Call to a member function query() on a non-object in
- How to Use Truffle to Deploy contracts on moonbeam
- How do you set, clear and toggle a single bit in C?