我有一个非常棘手的错误。
我将数据传递给函数。函数要做的就是获取该数据,并确保该数据在另一个页面上不存在。另一页上的数据是一个数组,如果其中没有任何内容,则为undefined。我想做的事情如下:
if($scope.profile.x.VALUE_IN_UNDEFINED_ARR_X === undefined)
{
//AKA theres nothing in the profile yet...add to users profile
}
else
{
if($scope.profile.x.name === myData.name)
{
//now theres a duplicate found
}
else
{
//add to users profile
}
}
我似乎无法使这种工作。对我来说,它总是在第一个if语句(未定义)中执行代码。然后,它会不断添加重复项。
我希望你们能帮助我编写一个循环程序,为我解决这个问题。
谢谢
最佳答案
使用typeof
检查未定义
typeof $scope.profile.x.VALUE_IN_UNDEFINED_ARR_X == 'undefined'
另外,“配置文件中没有任何内容”可以解释为“
$scope.profile
未定义”,如果是,则应检查此typeof $scope.profile == 'undefined'
关于javascript - Javascript/AngularJS/NodeJS-检查重复项吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31870188/