不知道你说的是不是这种效果。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
const arr = [
{
Chr: "chr",
Num: 1,
Kh: "h",
Fn_A: "a",
Fn_B: "b",
Fn_C: "c",
Fn_D: "d",
Ini_A: "a",
Ini_B: "b",
Ini_C: "c",
Ini_D: "d",
Syl_A: "a",
Syl_B: "b",
Syl_C: "c",
Syl_D: "d",
},
{
Chr: "chr",
Num: 2,
Kh: "h",
Fn_A: "a",
Fn_B: "b",
Fn_C: "c",
Fn_D: "d",
Ini_A: "a",
Ini_B: "b",
Ini_C: "c",
Ini_D: "d",
Syl_A: "a",
Syl_B: "b",
Syl_C: "c",
Syl_D: "d",
},
{
Chr: "chr",
Num: 3,
Kh: "h",
Fn_A: "a",
Fn_B: "b",
Fn_C: "c",
Fn_D: "d",
Ini_A: "a",
Ini_B: "b",
Ini_C: "c",
Ini_D: "d",
Syl_A: "a",
Syl_B: "b",
Syl_C: "c",
Syl_D: "d",
},
{
Chr: "chr",
Num: 4,
Kh: "h",
Fn_A: "a",
Fn_B: "b",
Fn_C: "c",
Fn_D: "d",
Ini_A: "a",
Ini_B: "b",
Ini_C: "c",
Ini_D: "d",
Syl_A: "a",
Syl_B: "b",
Syl_C: "c",
Syl_D: "d",
},
{
Chr: "chr",
Num: 5,
Kh: "h",
Fn_A: "a",
Fn_B: "b",
Fn_C: "c",
Fn_D: "d",
Ini_A: "a",
Ini_B: "b",
Ini_C: "c",
Ini_D: "d",
Syl_A: "a",
Syl_B: "b",
Syl_C: "c",
Syl_D: "d",
},
];
let arrFn = [];
let arrIni = [];
let arrSyl = []
let commonKeys = ['Chr', 'Num', 'Kh']
function filterChildHasKeys(arr, commonKeys, containKey) {
let res = [];
for (const item of arr) {
let resItem = {};
for (const key in item) {
if (commonKeys.includes(key) || key.includes(containKey)) resItem[key] = item[key]
}
res.push(resItem)
}
return res
}
arrFn = filterChildHasKeys(arr, commonKeys, 'Fn')
arrIni = filterChildHasKeys(arr, commonKeys, 'Ini')
arrSyl = filterChildHasKeys(arr, commonKeys, 'Syl')
console.log(arrFn);
console.log(arrIni);
console.log(arrSyl);
</script>
</body>
</html>