Bài toán kinh điển sử dụng three dots lấy tất cả các key của object, key same, plus (ok)
Ví dụ 1: Lấy tất cả các key của object (ok)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
var test = [{
key1: 1,
key2: 2
}, {
key2: 2,
key3: 3,
key6: 5
}, {
key3: 3,
key4: 4
}, {
key4: 4,
key5: 5
}];
// console.log(Object.getOwnPropertyNames(testkey));
var result = test.reduce(function(sum,now){
return {...sum,...now};
},{});
console.log(result);
</script>
</body>
</html>
Ví dụ 2: Mở rộng ví dụ tính tổng các key trùng nhau (P1)
Ví dụ 2: Mở rộng ví dụ tính tổng các key trùng nhau (P2)

Ví dụ 2: Tổng 2 khóa đối tượng giống nhau
https://stackoverflow.com/questions/42488048/how-can-i-sum-properties-from-two-objects
Bài toán 2:


Bài toán
Out format
https://stackoverflow.com/questions/42814907/group-values-with-the-same-key-in-an-array-of-objects
Ví dụ 3:

Một bài toán kinh điển xử lý bên kintone
Kết quả:


Last updated
Was this helpful?