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


Groups > comp.lang.javascript > #12194

Re: Empty array

From Dr J R Stockton <reply1208@merlyn.demon.co.uk>
Newsgroups comp.lang.javascript
Subject Re: Empty array
Date 2012-02-26 20:50 +0000
Organization Home
Message-ID <B4qvXYMZspSPFwE3@invalid.uk.co.demon.merlyn.invalid> (permalink)
References <0f481e7c-97b9-4c76-9660-321681876658@w9g2000vbv.googlegroups.com>

Show all headers | View raw


In comp.lang.javascript message <0f481e7c-97b9-4c76-9660-321681876658@w9
g2000vbv.googlegroups.com>, Sat, 25 Feb 2012 10:21:19, Archos
<raul.san@sent.com> posted:

>Is there any way to know if an array is empty? Without using its
>length method?

Since an array can have elements not indexed by 0 // (length-1),
A.length does not necessarily suffice.

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

If you are uninterested in non-enumerable elements, how about something
based on

        S = false
        for (J in A) S = true           //      ?

-- 
(c) John Stockton, nr London UK.  ?@merlyn.demon.co.uk  Turnpike v4.00  MIME
  Prof Timo Salmi's Usenet Q&A <URL:ftp://garbo.uwasa.fi/pc/link/tsfaqn.zip>
  TS FAQs via : http://www.uwasa.fi/~ts/http/ : tsfaq.html  quote margin &c.
  My page <URL:http://www.merlyn.demon.co.uk/news-use.htm> on usage of News.

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