Cho mảng 2 object, cần gộp thành 1 object và xóa property chk.
const err = [ { "chk" : true, "name": "test" }, { "chk" :true, "post": "test" } ];
Bước 1: Gộp object với Object.assign.
const errObj = Object.assign(...err);
Bước 2: Xóa property chk.
delete errObj['chk']; console.log(errObj);
Kết quả
{ name: 'test', post: 'test' }
Object.assign(...err) spread mảng thành các đối số: Object.assign({}, err[0], err[1]). Target rỗng ngầm tạo. delete xóa own property. Nếu muốn immutable: const {chk, ...rest} = errObj; (destructuring rest).