Looking for a way to extract the object value from a nested array object using JavaScript? If the sourcecountry
matches the country in the object, it should return the corresponding payment service.
Here is what I have attempted:
function getValue(source, obj) {
var list = obj.filter((cn) => {
return cn.country_from.filter((c) => {
return c.country == source;
});
});
}
var result = getValue(sourcecountry, obj);
var sourcecountry = "SG";
var obj = [
{
"country_from": [
{
"country": "SG",
"payment_service": [
{
"type": "bank transfer",
"speed": {
"unit": "days",
"number": "2"
},
}
]
},
{
"country": "TH",
"payment_service": [
{
"type": "credit",
"speed": {
"unit": "days",
"number": "1"
},
}
]
}
]
},
]
Desired Output:
Speed: 2 Days