1

How can I check if a JSON response is empty?

GetEmpName(){
  this.Emp.empservicecall()
    .subscribe(response => {
      console.log(response);
      this.name = response[0].name
    });
}

1 Answer 1

1

You can check if it is having values or not by

if(response && response.length > 0)

in order to fix compile time error, you need to define a type for the response, make it as any

 this.Emp.empservicecall()
    .subscribe((response : any) => {
Sign up to request clarification or add additional context in comments.

3 Comments

it is giving compile time error at line response.length
Property 'length' does not exist on type 'Object'
is it necessary to give type for response .

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.