我想要console.log或者用angularjs来定位数组中对象的字符串,但是它不起作用。请帮帮我,我对angularjs还是个新手。
这就是我要做的。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Profile Details AngularJS 1.X</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.6/angular.js"></script>
</head>
<body>
<div class="container" ng-app="DetailApp">
<div ng-controller="PostController">
</div>
</div>
<script>
var app = angular.module('DetailApp', []);
app.controller('PostController', function($scope) {
$scope.details = [{firstname: "Dave", lastname: "Del Rio"}, {firstname: "Gerald", lastname: "Kingston"}, {firstname: "Larry", lastname: "Jackson"}];
if ($scope.details.firstname == "Dave Del Rio") {
console.log("Hello Dave!")
}
else {
console.log("sorry, You're not welcome!")
};
});
</script>
</body>
</html>
我想在数组对象中指向名字“Dave”,但是它根本不起作用。
1条答案
按热度按时间ie3xauqp1#
可以使用
Array#some
检查数组中是否有任何元素与条件匹配。