function parseIdCard(idCard) { const year = idCard.substr(6, 4); const month = idCard.substr(10, 2); const day = idCard.substr(12, 2); const genderCode = idCard.substr(16, 1); const now = new Date(); const gender = genderCode % 2 === 0 ? '女' : '男'; const age = now.getFullYear() - Number(year); return { birthYear: year, birthMonth: month, gender: gender, age: age, }; } const idCard = '身份证号码'; // 替换为实际的身份证号码 const result = parseIdCard(idCard); console.log(result);