Path: csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: How to have multiple and undetermined number of arguments for function? Date: Mon, 10 Oct 2016 18:22:29 +0100 Organization: PointedEars Software (PES) Lines: 44 Message-ID: <9018847.nUPlyArG6x@PointedEars.de> References: <9abdc041-3977-470c-a886-b6ae885818c8@googlegroups.com> <87oa2ttk3f.fsf@bsb.me.uk> <441c0eb7-210d-4310-b58c-216a6a157dae@googlegroups.com> <7112eabe-6254-4ac4-b2f2-ff9d3d6cff5e@googlegroups.com> <718ec6b6-a194-48b3-87b9-3330b2f485d1@googlegroups.com> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1476120150 15391 eJwFwYEBwDAEBMCVKrwwDnn2H6F3UBd/1xxuWCwrnXpCjFmturKNIfLSQjFRXZ00tzeH/H4o2BHJ (10 Oct 2016 17:22:30 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 10 Oct 2016 17:22:30 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNyskBwDAIA7CVSs1hxiEE9h+h1VsGF+9QN1dbW6ldisS9hkFRybeD8CcTO5grYdLJ88CPVv6hsyQOdzTnA0Q4FSk= X-NNTP-Posting-Host: eJwFwYERAEEEBLCWGCxfDuv0X8InYVAwHQGPizv5THtPQGhdbnhzBbUzZXjkdNHo+fps/Qcs1hIf Cancel-Lock: sha1:16CD6c8hpRMox4yKE981pxEPi8k= Xref: csiph.com comp.lang.javascript:31555 Jake Jarvis wrote: > Am 10.10.2016 um 17:50 schrieb justaguy: >> […] >> I see. Thought, indexOf is sort of "contains". In the meantime, I have >> another statement, if (arguments[counter][0].indexOf('_row2')) { >> // do this an that >> } >> and it found it. How come? > > You need to look a bit closer, something is being done to the result of > indexOf. > The ! operator is applied to it. > > indexOf just returns -1 or position inside the string > > For what numbers that indexOf might return does ! give a true? > For a 0 (I stand) correct(ed). But now they have omitted the “!” operator, reversing the condition, so the block will be executed whenever the element either does not contain or does not start with "_row2". IOW, the proper way to do this is if (arguments[counter][0].indexOf("_row2") > -1) { /* do things if first element contains "_row2" */ } or if (arguments[counter][0].indexOf("_row2") >= 0) { /* do things if first element contains "_row2" */ } if arguments[counter] is a reference to an array-like object. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.