Skip to content
Advertisement

Remove data containing string from object

I want to ask how do I remove strings from data. Lets say I have a data:

JavaScript

how do I remove ManufacturerName and Device Name because they do not have numbers?

Advertisement

Answer

The simplest method – if you’re happy with mutating the object rather than creating a new one – is to iterate over the object properties, and try to coerce each value to a number. If it’s not a number remove the property.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement