我有一个想要过滤的对象。这是我使用的:
query = {
"teststring-123": "true",
"teststring-12344566": "false",
test: "true"
}
我想过滤查询,以便过滤后我只有:
query = {
"teststring-123": "true",
"teststring-12344566": "false"
}
$(query).each(function(index, value) {
$.each(value, function(i, v) {
if(i.indexOf('teststring-')==-1) {
// remove part of query object where index is this one
console.log(index)
}
});
});
我该如何处理这个问题?
最佳答案
您是否尝试删除所有不具有以“teststring-”开头的键的键值对?如果是这样的话...
for(var key in query){
if(query.hasOwnProperty(key) && key.indexOf('teststring-') === -1){
delete query[key];
}
}
关于javascript - 按键名过滤对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10452470/