Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28892
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: how to assure array is of composite objects |
| Date | 2015-11-16 15:49 +0100 |
| Organization | Liberty Development |
| Message-ID | <n2cqcp$bal$1@news.albasani.net> (permalink) |
| References | <435aa9ed-7cee-4418-aca3-9e6a2423d7ac@googlegroups.com> |
Tod Mar wrote:
> What would be the best (most efficient and effective) way to verify that an array is of composite objects and not of primitive or some other values?
> I assume it is to write logical code that just does what's required.
> However sometimes in other languages you can make sure the 'compile' (or in javascript or lint 'run'), never puts an invalid type into a variable.
> I'm curious if any comments on the preferred solution!
It seems like a task for the `every` method of arrays,
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every,
with a suitable check that implements your "requirement of "is of
composite objects and not of primitive or some other values". I am not
too sure what exactly you want to check there, but I guess it goes along
the lines of
myArray.every(function(item) { return !(typeof item == 'number' ||
typeof item == 'boolean' || ...); })
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to assure array is of composite objects Tod Mar <tamnt54@gmail.com> - 2015-11-16 06:34 -0800
Re: how to assure array is of composite objects Martin Honnen <mahotrash@yahoo.de> - 2015-11-16 15:49 +0100
Re: how to assure array is of composite objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-11-17 21:17 +0100
Re: how to assure array is of composite objects "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-11-16 20:07 -0800
csiph-web