Some Methods and Object Methods Special

Posted Jun 16, 20204 min read

  1. Concise three-purpose writing
    (1) Is there a methodName in serviceInfo?.methodName serviceInfo
    (2) serviceInfo?.parasTypes?.join(';')parasTypes in serviceInfo exists and is converted into a string operation
    Note 2:Restore array format parasTypes:parasTypes.split(';').filter(v => v)

  2. The input input box is required and the format is json


                   validator:async(rule, value, callback) => {
                     let out = value;
                     try {
                       out = JSON.parse(value);
                       if(typeof out !=='object') {
                           'The method template parameter format is incorrect, please use the order according to the method input {parameter 1:parameter value 1, parameter 2:parameter value 2 format json data',
                     } catch(e) {
                         'Method template parameter format is not correct, please use {parameter 1:parameter value 1, parameter 2:parameter value 2} format json data according to the method input parameters',
  3. Determine the function to enter at least one query condition
    params is a set of query conditions(a:'',b:'',c:''}

    const out = Object.assign(

       .filter(([k, v]) => k && v)
       .map(([k, v]) =>({ [k]:v })),

    if(Object.keys(out).length <1) {

       message.warn('At least one query condition needs to be entered');


5, Several methods of Object

(1) Usage of Object.assign()

 Syntax:Object.assign(target,  sources) target:target object, sources:source object, copy all enumerable attributes of the source object(source) to the target object(target). It requires at least two objects as parameters, the first parameter is the target object, and the following parameters are all source objects.
 Note:If the target object and the source object have the same name attribute, or multiple source objects have the same name attribute, the following attributes will overwrite the previous attributes.
      If there is only one parameter, Object.assign will directly return the parameter.
      If the parameter is not an object, it will first be converted into an object and then returned. However, since undefined and null cannot be converted into objects, if they are used as parameters, an error will be reported.
 Note:If non-object parameters appear in the source object's position(that is, non-first parameters), the processing rules are different. First of all, these parameters will be converted into objects, if they cannot be converted into objects, they will be skipped. This means that if undefined and null are not in the first parameter, no error will be reported. Other types of values  (ie, numeric, string, and Boolean) are not in the first parameter and will not report an error. However, except that the string will be copied into the target object in the form of an array, other values   will have no effect.
 Others:Object.assign only copies its own attributes. Non-enumerable attributes(enumerable is false) and inherited attributes will not be copied.
       For nested objects, the processing method of Object.assign is to replace, not add.
 For usage, please refer to:
 **Same usage as $.extend(), may differ in compatibility**

(2) Usage of Object.entries()

  The Object.entries method returns an array whose members are the array of key-value pairs of all enumerable properties of the parameter object itself(without inheritance)
   var obj = {foo:'bar', baz:42 };
   console.log(Object.entries(obj)); //['foo':'bar','bar':42]
   If the attribute name of the original object is a Symbol value, the attribute will be omitted
    `console.log(Object.entries({ [Symbol()]:123, foo:'abc' })); //[['foo','abc']]`

(2) Usage of Object.keys(obj)

    Parameters:the object whose enumeration of attributes is to be returned
    Return value:a string array representing all **enumerable properties of the given object**
    Usage:1. Process the object and return an enumerable attribute array
        let person = {name:"  ",age:25,address:"Shenzhen",getName:function(){}};
        console.log(Object.keys(person)); //['name','age','address','getName']
          2. Process the array and return the index value array
          let arr = [1,2,3,4,5,6];
          console.log(Object.keys(arr)); //["0", "1", "2", "3", "4", "5"]
          3. Process the string and return the index value array
          let str = "Hello ikun";
          console.log(Object.keys(str)); //["0", "1", "2", "3", "4", "5"]
          4. Common skills
          let person = {name:"  ",age:25,address:"Shenzhen",getName:function(){}};
           console.log(person[key]); //Zhang San, 25, Shenzhen, f(){}


  Usage:1. Return an array whose members are the key values   of all traversable properties of the parameter object itself(without inheritance)
            let obj = {foo:"bar",baz:20};
            console.log(Object.values(obj)); //["bar", 20]
        2. The order of the members of the returned array is consistent with the arrangement rules introduced in the traversal section of the property
            const obj = {100:"a", 2:"b", 7:"c"};
            console.log(Object.values(obj));//["b", "c", "a"]
       Note:The attribute with the attribute name as the value is traversed according to the size of the value, from small to large, so the return order is b, c, a.
       3. Object.values() will only traverse the traversable properties of the object itself
           const obj = Object.create({},{p:{value:10}});
           console.log(Object.values(obj)); //[]
      Note:The object attribute(attribute p) added by the second parameter of the Object.create method is not traversable by default if it is not explicitly declared, because the attribute of p describes the enumerable of the object is false by default, Object.values   will not return This property.
          So as long as the enumerable is changed to true, Object.values   will return the value of the attribute p.
          const obj = Object.create({},{p:{value:10,enumerable:true,configurable:true,writable:true,}})
         console.log(Object.values(obj)); //[10]
      4. Object.values   will filter the property whose property name is Symbol value
         //If the parameter of the Object.values   method is a string, an array of characters will be returned.
          Object.values({ [Symbol()]:123, foo:'abc' });
          console.log(Object.values('foo')); //["f", "o", "o"]
         Note:The string will first be converted into an array-like object. Each character of the string is a property of the object. Therefore, Object.values   returns the key value of each property, which is an array of individual characters
    5. If the parameter is not an object, Object.values   will first convert it to an object
         console.log(Object.values(42)); //[]
         console.log(Object.values(true)); //[]
         console.log(Object.values(undefined)); //error
         console.log(Object.values(null)); //error
         Note:Since the packaging objects for numeric and Boolean values   will not add non-inherited properties to the instance, Object.values   will return an empty array.