当我从集合中创建一个值字符串时,不会执行值null。只有当它是对象集合[i]的值时,我才需要在我的字符串中附加null。或者至少为什么没有通过null将不胜感激。
function truthCheck(collection, pre) {
// Is everyone being true?
var arr = '';
for ( i=0; i<collection.length; i++ ){
if ( pre in collection[i]){
arr += ' ' + Object.values(collection[i]);//Problem is here
}
}
arr += null; //If I append it after..
return arr; //This returns as I want it to. This return is for testing
//only.
arr = arr.trim();
var regex = /NaN|null|0|undefined|false/;
arr = arr.split(" ");
for ( i=0; i<arr.length; i++){
if( arr[i].search(regex) != -1 ){
arr.splice(i,1);
}
}
if ( arr.length == collection.length ){
return true;
}else{
return false;
}
}
truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat":
true},
{"name": "FastFoward", "onBoat": null}], "onBoat");
答案 0 :(得分:0)
for ( i=0; i<collection.length; i++ ){
if ( pre in collection[i] && collection[i][pre] ){
arr += ' ' + Object.values(collection[i]);
}
}