There is an object Obj from the property atr whose value is a string. I bring to the number and compare from the variable val , which is a number from 1 to 5.

Example: if val is 5, then remove anything less than or greater than 5 from the object.

It is impossible to remove an element from an object that meets or does not meet the comparison condition.

Tell me how to do this?

 Obj = { atr: "10", atr: "1", atr: "2", atr: "11", atr: "20", atr: "10" } 
  • are the same key names in the object? - Jean-Claude

1 answer 1

  delete Obj.attr; 

Or

  delete Obj['attr']; 

As a result, something will be released as:

 for (var key in Obj) { if (5 !== parseInt(Obj[key])) { delete Obj[key]; } } 
  • then the value of 5 lol will remain, maybe more correctly if (5 !== +Obj[key]) ? - Jean-Claude
  • In this case, you are right. But who knows what the incoming data is and what should happen - Pleshevskiy
  • the bracket is missing - Jean-Claude