Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: structure data : array Date: Wed, 16 Sep 2015 16:02:55 +0100 Organization: A noiseless patient Spider Lines: 39 Message-ID: <87lhc6e7a8.fsf@bsb.me.uk> References: <39d7a0ae-6b71-44a9-83eb-0e46928d6be3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="18001"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18TQZ78Pe6Y1/6aY0+FIBZ/y8O5U4Xb+S4=" Cancel-Lock: sha1:dQ/629IBA3dEVIbx+oLl56r5cPM= sha1:x5xBhRHQl1qO32UCJyyCwkbGGws= X-BSB-Auth: 1.4795d4f3e61d023d1286.20150916160255BST.87lhc6e7a8.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:28694 pinapalmieri@gmail.com writes: > If I have two array: > > arr1 = "Bananas", "Kiwi", "Mixed nuts" and > arr2 = 8,3,1 > > how i can create the following structure data? > > ['Bananas', 8], > ['Kiwi', 3], > ['Mixed nuts', 1] You are missing lots of []s. You have var arr1 = ["Bananas", "Kiwi", "Mixed nuts"]; var arr2 = [8, 3, 1]; and you want [ [ 'Bananas', 8 ], [ 'Kiwi', 3 ], [ 'Mixed nuts', 1 ] ] > Any suggestions? What have you tried so far? Do you have any constraints on the potability of the solution? Is this coursework? Maybe Array.prototype.zip = function (a) { return this.map(function (e, i) {return [e, a[i]]; }); }; does what you want. -- Ben.