javascript 数组对象中的console.log字符串,带有angularjs

zpgglvta  于 2023-02-21  发布在  Java
关注(0)|答案(1)|浏览(93)

我想要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”,但是它根本不起作用。

ie3xauqp

ie3xauqp1#

可以使用Array#some检查数组中是否有任何元素与条件匹配。

if ($scope.details.some(x => x.firstname === 'Dave' && x.lastname === 'Del Rio'))

相关问题