Having difficulty extracting the value of jersey_num from the JSON data below.
const json = [{
$: {
Type: "first_name"
},
_: "Evan"
}, {
$: {
Type: "last_name"
},
_: "Ferguson"
}, {
$: {
Type: "birth_date"
},
_: "2004-10-19"
}, {
$: {
Type: "weight"
},
_: "Unknown"
}, {
$: {
Type: "height"
},
_: "Unknown"
}, {
$: {
Type: "jersey_num"
},
_: "28"
}, {
$: {
Type: "real_position"
},
_: "Striker"
}, {
$: {
Type: "real_position_side"
},
_: "Centre"
}, {
$: {
Type: "join_date"
},
_: "2021-08-23"
}, {
$: {
Type: "country"
},
_: "Republic of Ireland"
}]
Attempted to retrieve using the code below, but got back an undefined result.
const jersey = Object.entries(json).find(([, e]) => Object.values(e).includes('jersey_num'))
console.log(jersey)
I suspect there might be something amiss in my code. Any guidance on how to properly extract the jersey_num value would be greatly appreciated.
EDIT
- Rectified the JSON object to correct format
- The desired value for extraction is '28' corresponding to Type: "jersey_num"