js objects and methods common attributes: copy an object, all object acquired a key value and all methods

Recording target some practical use and properties
// Object.assign () a plurality of objects of the same combined key behind the front cover 
const = {A target:. 1, B: 2}; 
const = {B Source:. 4, C:. 5}; 
const = returnedTarget Object. ASSIGN (target, Source); 
the console.log (returnedTarget) {// a:. 1, B:. 4, C:. 5} 
// cloning an object does not change the original object changes cloned object 
var obj = {a: 1} ; 
var = Object.assign Copy ({}, obj); 
obj.b = 2 
the console.log (obj); // {A:. 1, B: 2} 
the console.log (Copy); // {A:. 1 } 


// return all objects health key array 
const object1 = { 
  a: 'someString', 
  B: 42 is, 
  C: to false 
}; 
the console.log (Object.keys (object1)); // [ "a", " B "," C "] 

// returns an array of values of all objects 
const object2 = { 
  a: 'someString', 
  B: 42 is, 
  C: to false
};
console.log(Object.values(object2)); // ["somestring", 42, false]

  

Guess you like

Origin www.cnblogs.com/-kuige/p/11096820.html
Recommended