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 17:28:26 +0100 Organization: PointedEars Software (PES) Lines: 36 Message-ID: <2541393.e9J7NaK4W3@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> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1476116906 12825 eJwNysEBwEAEBMCWQuyinOD0X8Jl3oOXwnYjaFhsqadOh/Xo9xR7vJAjQ13JUwsdwaFrBP5wASmIEWM= (10 Oct 2016 16:28:26 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 10 Oct 2016 16:28:26 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYEBwDAEBMCVfPB0nBD2H6F3rgQ7jE7z9WXXxOQrqfGqubAOyRUdyOIgrEJtrJNtiL38NqcfBMTpH3USFeE= Cancel-Lock: sha1:56DWlABZ7Pg3/K3m7LRByS9yRzs= X-NNTP-Posting-Host: eJwFwYEBwCAIA7CXyihFz0HQ/09YEi5TJxVivHhWqzAYs977IhGeLPT5jDn3lDqoBfQjNf4DE7cQtg== Xref: csiph.com comp.lang.javascript:31553 Jake Jarvis wrote: > Am 10.10.2016 um 16:57 schrieb justaguy: >> I have one array as an argument for my the function in question, such >> array reads as ['grantor_row2','input','text',70]. >> >> In my loop for arguments, I have the following code with the intention of >> excluding this array, >> >> if (!arguments[counter][0].indexOf('_row2')) { >> console.log(arguments[counter][0]); >> } >> >> But the console did not return the value of 'grantor_row2'. What's >> wrong? > > You are actually checking if the first element starts with "_row2". No, they are very likely checking if the first item of the argument with zero-based index “counter”, arguments[counter][0], does _not_ start with "_row2". Very likely arguments[counter][0] is a String value, "grantor_row2", so arguments[counter][0].indexOf() would be equivalent to calling String.prototype.indexOf() on arguments[counter][0]. That method returns, as a Number value, the zero-based index of the start of its argument, the substring (“needle”), within its “this” value, the searched string (“haystack”); it returns -1 if the haystack does not contain the needle. And any Number value *other than 0* results in Boolean “false” when it is the operand of the Boolean Not (“!”) operator. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.