0

I have an object that I return when I have some data returned from query.

{
"responseMethod": "Method_Name",
"responseMessage": "",
"responseCode": 200,
"errorCode": "",
"responseData": {}
}

What I need if there is no data then it should show like below

  {
"responseMethod": "Method_Name",
"responseMessage": "",
"responseCode": 200,
"errorCode": "",
"responseData": []
}

I have used lodash.get to convert it but no success. please help

lodash.get(result,'result.responseData',[]);

The above one not working.

1 Answer 1

1

What about

var foo = {
  "responseMethod": "Method_Name",
  "responseMessage": "",
  "responseCode": 200,
  "errorCode": "",
  "responseData": {}
}
Object.keys(foo.responseData).length === 0 && (foo.responseData = [])
console.log(foo)

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

1 Comment

Thanks a lot @suresh Prajapati

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.