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

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

Remove array of objects from another array of objects

Remove array of objects from another array of objects

serialize Form

Sử dụng formdata constructor để convert form, FormData, array.from(). Kết hợp window.encodeURIComponent() để encode từng value trong form.