This is my array:
const array = [
{
"fare": "399.00",
"passenger": {
"age": "21",
"gender": "MALE",
"name": "Test1"
},
},
{
"fare": "399.00",
"passenger": {
"age": "21",
"gender": "FEMALE",
"name": "Test2"
},
}
]
How to map the object inside the array, and how to convert the object to the required output
Required output:
Test1(M), Test2(F)
Above contains "name" and gender - if its male then just "M" and if its female just "F"
As of now i tried,
array.map(o => ({ name: o.passenger.name, gender: o.passenger.gender })))
But how to convert this as expected output !
question from:
https://stackoverflow.com/questions/65880983/map-object-inside-array-in-javascript 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…