Object.fromEntries

es10,object

Object.entries và Object.fromEntries()

let leo = { name: 'pingan8787', age: 10};
let arr = Object.entries(leo);
console.log(arr);// [["name", "pingan8787"],["age", 10]]

let obj = Object.fromEntries(arr);
console.log(obj);// {name: "pingan8787", age: 10}

Map đổi thành Object

const map = new Map([ ['name', 'pingan8787'], ['age', 10] ]);
const obj = Object.fromEntries(map);
console.log(obj); // {name: "pingan8787", age: 10}

Array đổi thành Object

const arr = [ ['name', 'pingan8787'], ['age', 10] ];
const obj = Object.fromEntries(arr);
console.log(obj); // {name: "pingan8787", age: 10}

Có thể bạn đã miss một số snippets code

Rest Operator for Objects

Now we can use rest on the properties of an Object. It allows us to explicitly extract certain named variables, and assign any uncalled variables into a catchall Object.

Chuyển đổi thời gian trong javascript

Sử dụng Object.entries(), Array.prototype.filter() và Array.prototype.map(). Trả về định dạng ngày, giờ, phút với một miliseconds đã cho.

Ajax, call jQuery POST to node.js expressjs

Ajax, call jQuery POST to node.js expressjs

nullish coalescing javascript

nullish coalescing javascript

Spread Operator for Objects

Using the spread operator during an Object declaration will assign the properties of the referenced Object to the new Object.