【发布时间】:2017-06-22 06:04:02
【问题描述】:
function removeString(obj) {
var propertyArray = Object.values(obj); //make array of just properties
for(var i = 0; i < propertyArray.length; i++) {
if (typeof propertyArray[i] === "string") //find string
delete Object.keys(obj)[i]; //delete the key with the same index as the string
}
return obj;//return new object without string
}
var testObject = {size: 6, name: 'String', age: 20}
console.log(removeString(testObject)) //I want {size: 6, age: 20}
我希望上面的函数删除字段值为string,而不是返回的是原始对象。
对于任何阅读本文/愿意提供帮助的人,提前感谢您!
【问题讨论】:
标签: javascript string function object key