2
var linkArray = [
['boothsizeDiv_link', false],
['furnishingsprovidedDiv_link', false],
['electricalDiv_link', false],
['rentalfurnishingsDiv_link', false],
['gesgraphicsDiv_link', false],
['geslaborDiv_link', false],
['contractorDiv_link', false],
['carpetingDiv_link', false],
['boothlightingDiv_link', false],
['javitsDiv_link', false],
['boothsealDiv_link', false],
['mannequinsDiv_link', false],
['calcDiv_link', false]
];

How can i loop through this array to get all 'false' values from that array?

asked Mar 14, 2013 at 11:31

3 Answers 3

3

use a loop

for (var i=0;i<linkArray.length;i++)
{
 document.write(linkArray[i][1] + "<br>");
}
answered Mar 14, 2013 at 11:35
Sign up to request clarification or add additional context in comments.

Comments

0

If you just want a list of boolean values, the you can use this:

var falseValues = [];//this will be your list of false values
for(var i = 0; i < linkArray.length; i++){
 var link = linkArray[i];
 //test the value at array index 1 (i.e. the boolean part)
 if(!link[1]){
 falseValues.push(link[1]);//add the false to the list
 }
}
answered Mar 14, 2013 at 11:35

3 Comments

Do not use for ... in with regular arrays.
It sometimes breaks and is thus considered bad style. You can read stackoverflow.com/questions/500504/… for example.
@musefan have a look here stackoverflow.com/questions/500504/…
0

Judging by the variable name, the string values and the structure of your array, it might be a better approach to use object instead of array:

var linkObject = {
 boothsizeDiv_link: false,
 furnishingsprovidedDiv_link: false,
 electricalDiv_link: false,
 rentalfurnishingsDiv_link: false,
 gesgraphicsDiv_link: false,
 geslaborDiv_link: false,
 contractorDiv_link: false,
 carpetingDiv_link: false,
 boothlightingDiv_link: false,
 javitsDiv_link: false,
 boothsealDiv_link: false,
 mannequinsDiv_link: false,
 calcDiv_link: false
};

Now you can get the array of the boolean values like this:

var ret = [];
for (var propertyName in linkObject) {
 ret.push(linkObject[propertyName]);
}

But you can also get to a specific value like this:

linkObject['boothsizeDiv_link'] 

which yields false.

answered Mar 14, 2013 at 11:48

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.