0

JSON:

{
  "trackResponse": {
    "shipment": [{
      "warnings": [{
        "code": "TW",
        "message": "Tracking Information Not Found"
      }]
    }]
  }
}

In that string I want to retrieve "message" information. Please let know

1

1 Answer 1

1

use flatMap and Map

var data = {
  "trackResponse": {
    "shipment": [{
      "warnings": [{
        "code": "TW",
        "message": "Tracking Information Not Found"
      }]
    }]
  }
};
console.log(data.trackResponse.shipment.flatMap(i=>i.warnings.map(m=>m.message)))

Sign up to request clarification or add additional context in comments.

2 Comments

FYI, You are extracting it from an object, the question was about JSON...so You are missing a line ;)
Can we do this without flatmap and map

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.