var SelectedOptionId = 957;
$scope.array = [{"957":"1269"},{"958":"1265"},{"956":"1259"},{"957":"1269"},{"947":"1267"}]
有没有一种方法可以检查某个数组对象中是否存在某个值。我正在使用Angular和下划线。AngularJs - 检查数组对象中是否存在值
我已经尝试了这一切 -
if ($scope.array.indexOf(SelectedOptionId) === -1) {console.log('already exists')}
和
console.log($scope.array.hasOwnProperty(SelectedOptionId)); //returns false
和
console.log(_.has($scope.array, SelectedOptionId)); //returns false
http://stackoverflow.com/a/31775970/4323328 – tdog
注:'957'是一个关键,而不是看重 – Rajesh
是它是一个键被推入阵列 –