-3

I want to check if my object is null or the length is 0. I have tried something like this without any luck.

if (this.get('goodie.pincodes.firstObject') == null || this.get('goodie.pincodes.firstObject.pin').length == 0) {   
MMK
  • 3,673
  • 1
  • 22
  • 30
  • 1
    What does `this.get` do? What does `this.get('mobile.pincodes.firstObject.pin')` return? What exactly doesn't work? Do you get an error? What is currently happening and what do you expect to happen? You haven't provided any information that would enable us to help you. Please read [ask] and [mcve]. – Felix Kling Feb 08 '17 at 23:38
  • 2
    Possible duplicate of [Length of a JavaScript object](http://stackoverflow.com/questions/5223/length-of-a-javascript-object) – Sebastian Simon Feb 08 '17 at 23:38
  • Sorry. I expect the statement to be true if either there is no pincode object or the length of the pin is == 0. I know the first part of the statement works but not the second. If i have a pincode object with the pin length == 0 i do not enter the if statement. – Rene Jespersen Feb 08 '17 at 23:44
  • So, `this.get('goodie.pincodes.firstObject.pin')` returns what? An object? An object with property `length`? An array? – Felix Kling Feb 08 '17 at 23:47
  • this.get('goodie.pincodes.firstObject.pin') returns the value of a pincode. Ex. "1234" – Rene Jespersen Feb 09 '17 at 00:05
  • So it returns a *string* and you are testing the length of a string. And that's not what you want? Why are you asking about getting the "object length"? Which object are you talking about then? Instead of us trying to figure out you really mean, please provide a [mcve]. – Felix Kling Feb 09 '17 at 06:02

1 Answers1

0

I solved this in a different way. Making sure that entries with no length allways returns null. Then only asking if the object is null.

this.get('goodie.pincodes.firstObject') == null