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


Groups > comp.lang.javascript > #38500

Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it?

Newsgroups comp.lang.javascript
Date 2020-07-11 22:41 -0700
References <361f78f8-7ff6-4a2c-a3a6-6e4211cdc9d8o@googlegroups.com>
Message-ID <46ffdb1c-eaac-41a8-8b91-facd2f3c0051o@googlegroups.com> (permalink)
Subject Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it?
From luserdroog <luser.droog@gmail.com>

Show all headers | View raw


On Saturday, July 11, 2020 at 8:26:44 PM UTC-5, JRough wrote:
> Map function works in playcode.io sandbox but it doesn't work in JS console.  Is that because playcode has babel?  In anycase, in playcode.io it says it has a bug but it still works.  How to fix the bug on the last line?  Error message is:error: unknown: Unexpected token, expected "," (8:28)
> 
> 
> let users = [{name: 'John', gender: 'M'}, 
> {name: 'David', gender: 'M'}, 
> {name: 'Ashok', gender: 'M'}, 
> {name: 'Naveen', gender: 'M'}, 
> {name: 'Maddy', gender: 'F'}, 
> {name: 'Mathilda', gender: 'F'}];
> users.map((user ) => ({ user.gender ==="F" ? user:''})
> 
> thanks,

JJ has addressed your syntax, but have you considered 'filter' instead 
of 'map'? It's hard to imagine what those empty strings do for you.

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


Thread

Map function works but has a "UNEXPECTED TOKEN" error how to fix it? JRough <janis.rough@gmail.com> - 2020-07-11 18:26 -0700
  Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? JJ <jj4public@vfemail.net> - 2020-07-12 10:40 +0700
    Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? JRough <janis.rough@gmail.com> - 2020-07-12 10:46 -0700
      Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? James Kirk <noneya.invalid@gmail.com> - 2020-07-12 14:04 -0400
        Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? JRough <janis.rough@gmail.com> - 2020-07-12 11:17 -0700
      Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? JRough <janis.rough@gmail.com> - 2020-07-12 11:14 -0700
  Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? luserdroog <luser.droog@gmail.com> - 2020-07-11 22:41 -0700
    Re: Map function works but has a "UNEXPECTED TOKEN" error how to fix it? JRough <janis.rough@gmail.com> - 2020-07-12 11:17 -0700

csiph-web