Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #10631
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post2.news.xs4all.nl!newszilla.xs4all.nl!not-for-mail |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Set some elements of an array |
| From | "Evertjan." <exjxw.hannivoort@interxnl.net> |
| References | <94303e95-1469-4608-b582-33dec96f7e39@p21g2000yqm.googlegroups.com> <1u41i7ttl9evaofuq75ffktd4c9lracvbg@4ax.com> |
| Message-ID | <Xns9FE7687CD2E85eejj99@194.109.133.133> (permalink) |
| User-Agent | Xnews/2009.05.01 |
| Date | 27 Jan 2012 09:16:19 GMT |
| Lines | 34 |
| NNTP-Posting-Host | 188.142.37.124 |
| X-Trace | 1327655779 dreader34.news.xs4all.nl 19737 ehannivo/188.142.37.124:59552 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.javascript:10631 |
Show key headers only | View raw
Gene Wirchenko wrote on 26 jan 2012 in comp.lang.javascript:
> var b1=[1,2,3,4,0,0,0,0,0,0,0,0,0,0,0,0];
>
> or
>
> var b1=[1,2,3,4];
> for (var i=4; i<16; i++)
> b1[i]=0;
A variation:
b = [1,2,3,4].concat([0,0,0,0,0,0,0,0,0,0,0,0]);
document.write(b.length + ': ' + b);
// 16: 1,2,3,4,0,0,0,0,0,0,0,0,0,0,0,0
====================
If the added content is not all zero but repeating
concat() is a good choice:
var b=[1,2,3,4];
for (var i=4; i<16; i+=2)
b = b.concat([9,55]);
document.write(b.length + ': ' + b);
// 16: 1,2,3,4,9,55,9,55,9,55,9,55,9,55,9,55
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Set some elements of an array Archos <raul.san@sent.com> - 2012-01-25 14:05 -0800
Re: Set some elements of an array "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-25 16:30 -0800
Re: Set some elements of an array Gene Wirchenko <genew@ocis.net> - 2012-01-25 15:54 -0800
Re: Set some elements of an array "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-01-27 09:16 +0000
Re: Set some elements of an array Dr J R Stockton <reply1204@merlyn.demon.co.uk> - 2012-01-27 20:39 +0000
csiph-web