Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #33586
| Path | csiph.com!aioe.org!news.mb-net.net!open-news-network.org!.POSTED.29.227.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Find object in array |
| Date | Mon, 17 Jul 2017 20:06:27 +0200 |
| Organization | PointedEars Software (PES) |
| Lines | 28 |
| Message-ID | <3355443.kQq0lBPeGt@PointedEars.de> (permalink) |
| References | <Ca-dndZsZ7OrtvbEnZ2dnUU7-e3NnZ2d@westnet.com.au> <okfajg$fug$1@news.albasani.net> <okim6r$1849$1@gioia.aioe.org> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| Injection-Info | gwaiyur.mb-net.net; posting-host="29.227.197.178.dynamic.wless.zhbmb00p-cgnat.res.cust.swisscom.ch:178.197.227.29"; logging-data="3279"; mail-complaints-to="abuse@open-news-network.org" |
| User-Agent | KNode/4.14.2 |
| X-Face | %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v |
| X-User-ID | U2FsdGVkX194axoOQ9fSJp72Tpi/vgStIFm84+UO/JATtkS1Qt2NZA== |
| Cancel-Lock | sha1:0PGP9Nfkbsg+ctcVqFihLU+D5Hk= |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== |
| Xref | csiph.com comp.lang.javascript:33586 |
Show key headers only | View raw
JR wrote:
> Martin Honnen wrote:
>> If you have an array "a" and want to find items meeting a specific
>> condition then you can use
>> a.filter(o => o.id == 1)
>> to get an array of those objects meeting the filter condition.
>>
>> var a = [{id: 1, data: 'foo'}, {id: 2, data: 'bar'}, {id:1, data:
>> 'baz'}]; a.filter(o => o.id == 1)
>
> Great!
>
> Another possibility is the find() method [1]:
>
> a.find(el => el.id === 1);
>
> [1]
> <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find>
In contrast to .filter(), .find() does not return a reference to a new Array
instance of matching elements (here: object references), but only the first
matching element.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Find object in array Andrew Poulos <ap_prog@hotmail.com> - 2017-07-16 19:00 +1000
Re: Find object in array Martin Honnen <martin.honnen@gmx.de> - 2017-07-16 11:11 +0200
Re: Find object in array JR <jrfaqcom@gmail.com> - 2017-07-17 12:47 -0300
Re: Find object in array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-07-17 20:06 +0200
Re: Find object in array Andrew Poulos <ap_prog@hotmail.com> - 2017-07-16 19:14 +1000
Re: Find object in array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-07-17 01:30 +0200
Re: Find object in array Dr J R Stockton <J.R.Stockton@physics.org> - 2017-07-16 15:13 -0700
Re: Find object in array Andrew Poulos <ap_prog@hotmail.com> - 2017-07-17 14:49 +1000
Re: Find object in array "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-07-17 13:53 +0200
Re: Find object in array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-07-17 14:29 +0100
Re: Find object in array JR <jrfaqcom@gmail.com> - 2017-07-18 13:02 -0300
csiph-web