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

Getting the last element of a split string array

Getting the last element of a split string array

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.

Đếm có bao nhiêu items giống nhau trong một array

reduce javascript. Đếm có bao nhiêu items giống nhau trong một array

nullish coalescing javascript

nullish coalescing javascript

String.prototype.trimEnd

trimEnd() Phương thức xóa khoảng trắng từ đầu chuỗi và trả về một chuỗi mới. Có nghĩa là trimEnd() xoá những ký tự space bên phải mà không làm thay đổi chuỗi gốc.