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

Clone Objects in JavaScript

3 Ways to Clone Objects in JavaScript

Object.fromEntries

Object.fromEntries Là một phương thức mới được giới thiệu trong ES10 được sử dụng để chuyển đổi từ list có dạng key và value thành những objects.

Ajax, call jQuery POST to node.js expressjs

Ajax, call jQuery POST to node.js expressjs

using async/await to catch errors

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.