Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #41164
| From | doctor@doctor.nl2k.ab.ca (The Doctor) |
|---|---|
| Newsgroups | comp.lang.php, comp.lang.javascript |
| Subject | Re: Stripping [ ] from JSON arrays |
| Date | 2023-01-11 16:18 +0000 |
| Organization | NetKnow News |
| Message-ID | <tpmngk$12k$94@gallifrey.nk.ca> (permalink) |
| References | <tpiebr$cso$64@gallifrey.nk.ca> <1rb3ua6kn88tn.objz7l6azwbd.dlg@40tude.net> <63bedf36$0$3100$426a34cc@news.free.fr> |
Cross-posted to 2 groups.
In article <63bedf36$0$3100$426a34cc@news.free.fr>,
Elhwen Dico <elhwen.dicote@gmail.com> wrote:
>Le 10/01/2023 à 05:29, JJ a écrit :
>> On Tue, 10 Jan 2023 01:17:47 -0000 (UTC), The Doctor wrote:
>>>
>>> How do I strip unnecessary [] ?
>>
>> I'd use array's `reduce()` for that. e.g.
>>
>> var resultObj = theArray.reduce((res, obj) => Object.assign(res, obj), {});
>
> const array = [
> [0, 1, 2], [], ["tutu"], undefined
> ];
>
> const result = array.filter(
> (tab) => (tab && tab.length));
>
> console.log(result);
>
>-> [ [ 0, 1, 2 ], [ 'tutu' ] ]
>
> you could improve filter callback to check that array members are arrays.
giving an update, I finally found someone at Moneris to work with.
I hate bad doumentation.
--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
Birthdate: 29 Jan 1969 Redhill, Surrey, England Beware https://mindspring.com
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Stripping [ ] from JSON arrays doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-01-10 01:17 +0000
Re: Stripping [ ] from JSON arrays JJ <jj4public@outlook.com> - 2023-01-10 11:29 +0700
Re: Stripping [ ] from JSON arrays Elhwen Dico <elhwen.dicote@gmail.com> - 2023-01-11 17:09 +0100
Re: Stripping [ ] from JSON arrays doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-01-11 16:18 +0000
Re: Stripping [ ] from JSON arrays Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2023-01-10 08:10 +0000
csiph-web