In postman, if i get a responsebody of [] i want to do an "IF" statement but if the response is anything else it will do the "ELSE" statement however, i cannot make it do the "IF" suggesting that jsonData == "[]" is wrong.
CodePudding user response:
Problem
Your response is an array, not a String, so you cann't compare jsonData == "[]"
Solution
Check this array whether has length = 0 or not, you can choose one of 2 below approaches.
if (Array.isArray(jsonData) && jsonData.length === 0)
or
if (Array.isArray(jsonData) && !jsonData.length)