JSON FILTER TEST

by George Obregon

HTML

<script>
    
    var _consoleLog = console.log;
    
    console.log = function(){
        var name = _consoleLog.apply(console,arguments);
        var str = "";
        for(var index in arguments){
            if(Array.isArray(arguments[index])){
               arguments[index] = arguments[index].map(function(item){
                    if(typeof item == "object"){
                        item = JSON.stringify(item,null,4);
                    }
    
                    return item;
               });
               str += arguments[index]+" ";
                
            } else if(typeof arguments[index] == "object"){
                str = JSON.stringify(arguments[index],null,4);
            } else {
                str += arguments[index]+" ";
            }
        }
        $('body').append(str);
    }
   
</script>

JavaScript

var arr = [{"timestamp":"92301","city":"ADELANTO","state":"CA","area":"8","phone":"(818)988-0022"},{"timestamp":"91301","city":"AGOURA HILLS","state":"CA","area":"4","phone":"(818)988-0022"},{"timestamp":"Row: 4","city":"ALAMEDA","state":"CA","area":"14","phone":"(415)236-0010"},{"timestamp":"94706","city":"ALBANY","state":"CA","area":"13","phone":"(415)236-0010"},{"timestamp":"91801","city":"ALHAMBRA","state":"CA","area":"3","phone":"(323)953-8100"},{"timestamp":"91803","city":"ALHAMBRA","state":"CA","area":"3","phone":"(323)953-8100"},{"timestamp":"92656","city":"ALISO VIEJO","state":"CA","area":"6","phone":"(323)953-8100"},{"timestamp":"91001","city":"ALTADENA","state":"CA","area":"3","phone":"(323)953-8100"},{"timestamp":"95002","city":"ALVISO","state":"CA","area":"14","phone":"(415)236-0010"},{"timestamp":"94503","city":"AMERICAN CANYON","state":"CA","area":"15","phone":"(415)236-0010"}];
    
var newArr = [];

for(var i= 0, l = arr.length; i< l; i++){
    if(arr[i].timestamp === "95002" ){
		newArr.push(arr[i]);
	}
}

console.log("Filter results:",newArr);