Path: csiph.com!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Get object from one of its values Date: Tue, 20 Dec 2016 23:10:13 +0100 Organization: PointedEars Software (PES) Lines: 27 Message-ID: <1771227.kXSN5OTJKJ@PointedEars.de> References: <2298053.9Mp67QZiUf@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1482271814 4129 eJwNx8EBwCAIA8CVQEiUcUBh/xHa+x2MyrudoGMwJ5LlA0i+1zsWxbi8TeovwuRWctp11G2dDxlAENE= (20 Dec 2016 22:10:14 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Tue, 20 Dec 2016 22:10:14 +0000 (UTC) User-Agent: KNode/4.14.2 Cancel-Lock: sha1:bD/e7vSwKdHptrvETHqeFJqi0Bg= X-User-ID: eJwNjMENwDAIxFYKgTvKOAmE/UcoDz8sS4ZSmG4EDY1mr7i8WvW1ky9EDAd3uz1Ej+2QWG+xPHeW5lTmcDiX/AFEphUP X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. if (!obj.hasOwnProperty("childArray") || obj.childArray.indexOf(5) < 0) > { > return false; > } > > return true; This can be simplified to return (obj.hasOwnProperty("childArray") && obj.childArray.indexOf(5) > -1); or return (obj.childArray && obj.childArray.indexOf(5) > -1); if it does not matter that the “childArray” property is inherited. (But it is assumed here that it holds a reference to an Array instance, and that the Array.prototype.indexOf() method of ES 5+ is implemented.) -- PointedEars FAQ: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.