如何从对象中删除空键值对 像
angular.module('myApp').controller('LoginController', LoginCtrl);
LoginCtrl.$inject = ['$q', '$scope', '$location', '$routeParams', '$window', 'authService', 'regService'];
function LoginCtrl($q, $scope, $location, $routeParams, $window, authService, regService) {
//some code here
}
将成为obj = {name: 'asd','':'',pass: true}
提前致谢
答案 0 :(得分:3)
试试这个delete obj[''];
有关delete
运算符的更多信息:
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/delete
答案 1 :(得分:1)
你可以试试:
delete obj[''];
答案 2 :(得分:1)
在一行中:
delete obj[''];
或
for(property in obj){
if(property == ""){
delete obj[property]
}
}