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]
];

我如何循环遍历该数组以从该数组中获取所有“假”值?

4

3 回答 3

3

使用循环

for (var i=0;i<linkArray.length;i++)
{
     document.write(linkArray[i][1] + "<br>");

}
于 2013-03-14T11:35:46.237 回答
0

如果你只想要一个布尔值列表,你可以使用这个:

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
    }
}
于 2013-03-14T11:35:40.017 回答
0

从变量名、字符串值和数组结构来看,使用对象而不是数组可能是更好的方法:

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
};

现在您可以像这样获取布尔值的数组:

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

但是你也可以像这样得到一个特定的值:

linkObject['boothsizeDiv_link'] 

产生false

于 2013-03-14T11:48:57.233 回答