Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #12185

Re: Empty array

From Gregor Kofler <usenet@gregorkofler.com>
Newsgroups comp.lang.javascript
Subject Re: Empty array
Date 2012-02-25 23:02 +0100
Organization A noiseless patient Spider
Message-ID <jiblou$qum$1@dont-email.me> (permalink)
References <0f481e7c-97b9-4c76-9660-321681876658@w9g2000vbv.googlegroups.com>

Show all headers | View raw


Am 2012-02-25 19:21, Archos meinte:
> Is there any way to know if an array is empty? Without using its
> length method?

There is no length "method". Only a length property.
What do you mean by "empty"? That it has length zero? Then check the
length property.

> I thought that could work the nex one:
> 
> var a = []; if (a === []) {console.log("empty")}

You can't compare arrays (or any object within JS) this way. In this
case you compare an array reference stored in a with an ad-hoc created
array - which is a different object - and the comparison will always
return false. (If two variables reference the same object, their
equality comparison will return true).

Gregor


-- 
http://vxweb.net

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Empty array Archos <raul.san@sent.com> - 2012-02-25 10:21 -0800
  Re: Empty array Gregor Kofler <usenet@gregorkofler.com> - 2012-02-25 23:02 +0100
  Re: Empty array Dr J R Stockton <reply1208@merlyn.demon.co.uk> - 2012-02-26 20:50 +0000
    Re: Empty array "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-27 14:46 +0000
      Re: Empty array Dr J R Stockton <reply1209@merlyn.demon.co.uk> - 2012-02-28 23:42 +0000
  Re: Empty array Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-02-27 07:30 -0800
    Re: Empty array Dr J R Stockton <reply1209@merlyn.demon.co.uk> - 2012-02-28 22:00 +0000
      Re: Empty array Gene Wirchenko <genew@ocis.net> - 2012-02-28 17:20 -0800
        Re: Empty array Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-02-29 01:23 -0800
          Re: Empty array Gene Wirchenko <genew@ocis.net> - 2012-02-29 14:12 -0800
        Re: Empty array Dr J R Stockton <reply1209@merlyn.demon.co.uk> - 2012-03-01 21:20 +0000

csiph-web