Javascript Essentials ES6

Object to String Array of the object keys

const strArrKeys = Object.keys(jsObjectVariable);

Array from object values

jsObjectVariable = {
  one : 1,
  two: 2,
  three: {
    temp1: "t1",
    temp2: "t2"
}
}
const strArr = Object.keys(jsObjectVariable) // Returns ARRAY of the keys
                 .map(k =>  jsObjectVariable[k] ); // Retruns an Array of values 
console.log(strArr);

const strArr2 = Object.keys(jsObjectVariable) // Returns ARRAY of the keys
                 .map(k => {  return jsObjectVariable[k] }
                 ); // Retruns an Array of values 
console.log(strArr2);

jsARRVariable  = [(one => 1),(two => 2)];

const strArr3 = jsARRVariable.map((k,v) => {return v;} ); // Returns array of values
console.log(strArr3);

Make a copy of the object.

cont newObject = {...oldObject};

MORE TO COME

Leave a Reply

Your email address will not be published. Required fields are marked *


CAPTCHA Image
Reload Image