0

Im getting returned JSON like this

{"d":{"questions":[],"stuff":"value"}}

how do I check for questions and do something if its blank/empty IE the [] with nothing inside?

This doesn't work:

var msg = data.d.IsErrorExists;
var quetions = data.d.questions;
if (msg == 'false' && questions === '[]') {
        //do stuff based on msg=false and questions=[]
      }

1 Answer 1

1

You could check if the length of the array is greater than zero:

 if (questions.length){
 }
Sign up to request clarification or add additional context in comments.

3 Comments

So if (msg == 'false' && questions.length) {//do something }?
probably if (!msg && !questions.length)
so that will check for NO msg and No qustions, just remove the first ! to check FOR msg and no questions right?

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.