0

I have this array of objects (around 100) in JS and all I need to do is to remove objects with value of "Number of drops" less than 4, but I'm really struggling with the removal of the objects that don't fit the criteria. The array looks like this:

[
      {
        Domain: 'devonsfinest.co.uk',
        'Number of drops': 2,
        'Number of changes': 6,
        'Period in years': 4,
        'Parked before': 1,
        'Detailed history link': 'https://completedns.com/dns-history/?domain=devonsfinest.co.uk'
      },
      {
        Domain: 'mattresses-uk.co.uk',
        'Number of drops': 2,
        'Number of changes': 4,
        'Period in years': 4,
        'Parked before': 0,
        'Detailed history link': 'https://completedns.com/dns-history/?domain=mattresses-uk.co.uk'
      },
      {
        Domain: 'ukauctionguides.co.uk',
        'Number of drops': 4,
        'Number of changes': 13,
        'Period in years': 4,
        'Parked before': 1,
        'Detailed history link': 'https://completedns.com/dns-history/?domain=ukauctionguides.co.uk'
      }
    ]

Thank you in advance!

freemanfl
  • 55
  • 6
  • Did you try with filter method? – Raffaele Jul 29 '21 at 10:11
  • have a look here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter. you can use filter to filter out the objects you don't want to have. – Strahinja Ajvaz Jul 29 '21 at 10:11
  • Also: [How can I access a JavaScript object which has spaces in the object's key?](https://stackoverflow.com/questions/8317982/how-can-i-access-a-javascript-object-which-has-spaces-in-the-objects-key) – Ivar Jul 29 '21 at 10:16
  • Yes, thanks for the help a lot guys! Do i need to remove this post? – freemanfl Jul 29 '21 at 10:20
  • That's completely up to you @freemanfl. If you think it adds value for future visitors you could leave it. Otherwise you can remove it. – Ivar Jul 29 '21 at 10:28
  • Thanks! Can I also pls ask you, how do I console log only one same proprety value from every object? Like in the example above I want to only show 'Number of drops' property of every object – freemanfl Jul 29 '21 at 10:30
  • You can use [`Array.prototype.map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) to map each object to one property in an array. If you want to log you could just use a loop and on each iteration log the property of your choosing. – Ivar Jul 29 '21 at 10:34

0 Answers0