JavaScript Condition to check if variables exist in an array of objects

Using Array.filter might be cleaner, like so:

var activeCheck = "false";
var out = obj1.filter(function(item) {
  return item.active === activeCheck && data.includes(item.id);
});
Answer:1

With underscore, use the _.filter function:

var isActive = "false"; // get that value dynamically
var result = _.filter(obj1, function(value) {
  return data.indexOf(value.id) > -1 && value.Active === isActive;
});

var data = ["004", "456", "333", "555"];


obj1 = [{
  id: "004",
  name: "Rick",
  Active: "false"
}, {
  id: "005",
  name: 'david',
  Active: "false"
}];

var result = _.filter(obj1, function(value) {
  return data.indexOf(value.id) > -1 && value.Active === "false";
});

console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
Answer:2

How can i solve the issue of scope of variable in the below case. Myapp.controller('MyController', ['$scope', function ($scope) { var formvalues = {}; $scope.somebuttonclick = function()...

How can i solve the issue of scope of variable in the below case. Myapp.controller('MyController', ['$scope', function ($scope) { var formvalues = {}; $scope.somebuttonclick = function()...

  1. variable scope javascript issue

I created a bootstrap-compass project with the following yeoman generator: https://www.npmjs.com/package/generator-bootstrap-compass You can see the file structure in the link. How do I add the ...

I created a bootstrap-compass project with the following yeoman generator: https://www.npmjs.com/package/generator-bootstrap-compass You can see the file structure in the link. How do I add the ...

I'm using SweetAlert2 and the 7th example on this page: Go to 7th example below to see it in action this one: swal({ title: 'Are you sure?', text: 'You will not be able to ...

I'm using SweetAlert2 and the 7th example on this page: Go to 7th example below to see it in action this one: swal({ title: 'Are you sure?', text: 'You will not be able to ...

  1. sweet alert redirect after click ok
  2. sweet alert redirect on confirm
  3. sweet alert redirect after timer
  4. sweet alert redirect after confirm
  5. sweet alert redirect
  6. sweet alert redirect on ok
  7. sweet alert redirect page
  8. sweet alert redirect after ok php
  9. sweet alert redirect url
  10. php sweetalert redirect
  11. js sweetalert redirect
  12. sweet alert click ok redirect
  13. sweet alert onclick ok redirect
  14. sweet alert success redirect
  15. redirect after sweet alert
  16. sweet alert then redirect
  17. sweetalert2 redirect
  18. sweetalert2 redirect after click ok
  19. redirect sweetalert button
  20. redirect page after sweet alert

I'd like to achieve this effect via css and possibly jQuery. That is to create a search bar that is hidden, and will nicely slide to the left on clicking the search icon in the label. But I just ...

I'd like to achieve this effect via css and possibly jQuery. That is to create a search bar that is hidden, and will nicely slide to the left on clicking the search icon in the label. But I just ...