473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to verify that all objects in an array meet a single requirement?

2
I am very new to javascript (and programming in general, for that matter), and I am having difficulty reworking this bit of code:

Expand|Select|Wrap|Line Numbers
  1. if ((a1 == 'valid') && (a2 == 'valid') && (a3 == 'valid') && (a4 == 'valid')) {
  2.     // do something
  3. }
  4.  
Once I create the array...

Expand|Select|Wrap|Line Numbers
  1. var theArray = [a1, a2, a3, a4]
  2.  
...how do I loop through and check to see if each object in the array (not just one) is valid? For instance:

Expand|Select|Wrap|Line Numbers
  1. if (theArray[all] == 'valid') {
  2.     // do something
  3. }
  4.  
I suspect the answer to this question is somewhat rudimentary, but I was unable to find it anywhere else in the forum. Perhaps I am not using the correct terms in my search? In any case, any guidance would be much appreciated.

Thanks,
Matthew
Apr 14 '08 #1
2 1039
pronerd
392 Expert 256MB
...how do I loop through and check to see if each object in the array (not just one) is valid? For instance:
Expand|Select|Wrap|Line Numbers
  1.     var theArray = [a1, a2, a3, a4]
  2.     for( var i = 0; i < theArray.length; i++ ) {
  3.         var someValue = theArray[i];
  4.         if ( someValue == 'valid' ) {
  5.             // do something
  6.         }
  7.     }
  8.  
  9. }
  10.  
Apr 14 '08 #2
mcg365
2
Thanks for the response. I must be dumber than I realized, because I am still unable to get my code to work. Please have a look at what I am working with:

Expand|Select|Wrap|Line Numbers
  1. function updateMaster() {
  2.     var opt0 = parent.document.getElementById('opt0').value
  3.     var opt1 = parent.document.getElementById('opt1').value
  4.     var opt2 = parent.document.getElementById('opt2').value
  5.     var optArray = new Array(opt0,opt1,opt2)
  6.     for (i=0; i <= 11; i++) {
  7.         var x = optArray[i]
  8.         // if ALL are CHECKED
  9.         if (x == '0') {
  10.             parent.document.getElementById('clickValue').value = 'reset'
  11.             }
  12.         // if ALL are UNCHECKED
  13.         else if (x != '0') {
  14.             parent.document.getElementById('clickValue').value = '9'
  15.         }
  16.         // if SOME are UNCHECKED
  17.         else {
  18.             parent.document.getElementById('clickValue').value = '-9'
  19.         }
  20.     }
  21. }
  22.  
I have tried a million variations of this, but each and every time, no matches are found and '9' is returned. Now, my morale has sunken low enough to warrant another shameless cry for help.

Any suggestions? Thanks again.
Apr 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Venkat | last post by:
Hi All, I need to copy strings from a single dimensional array to a double dimensional array. Here is my program. #include <stdio.h> #include <stdlib.h>
2
by: ES Kim | last post by:
MEC++ Item 17 explains how to require an object be constructed only on heap. No automatic, no static objects, that is. But I can't find how to enforce the requirement for derived classes too. 1....
1
by: Michael Hill | last post by:
I am creating a page where I want to dynamically fillin the contents of a table based on user selections. The page is created from a cgi. I have a number of rows, say 150 that I want to hide...
2
by: Wendell Wilkie | last post by:
I am working with a 3rd party unmanaged dll, and I need to pass an array of char* as an argument. I can used fixed to get a single char* as follows: char buf = new char; fixed (char* p = buf)...
5
by: Shibu | last post by:
Hi, I have a situation where I need to convert business objects to a flat table. The reverse is also required. I am using c# and Oracle ODP. I am looking for an easier method to do the below...
3
by: ExclusiveResorts | last post by:
Can the CallContext be used reliably for storing request specific data? We are developing an application library that uses the CallContext to keep an IdentityMap (hashtable of business objects...
1
by: Nemisis | last post by:
Hi everyone, If i have 3 objects as below. objectA A_id A_Name B_id objectB
3
by: pblack9455 | last post by:
I have a simple requirement to bind a small ArrayList of (ItemLine) Objects to a GridView control. The Gridview renders on the page and allows me to click update/edit buttons...however the data...
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.