0

I have a very large array of objects and some of the objects have a nameless property. What is an efficient way to remove the property?

[ 
  ...
  {
    "phone_number": "***-***-****",
    "category": "Abc",
    "link_to_company": "www.example.com",
    "email": "test@test.com",
    "company_name": "test company",
    "": "123", // this need to be removed
    "status": 1
  },
  ...
]
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
Shafqat Jamil Khan
  • 1,039
  • 1
  • 9
  • 17

1 Answers1

2

A map function should do it.

array.map(v => { delete v[""]; return v })

Christofer Eliasson
  • 32,939
  • 7
  • 74
  • 103
  • thanks for the answer but what if there are multiple empty keys? – Shafqat Jamil Khan Mar 26 '21 at 19:11
  • 1
    @ShafqatJamilKhan It's not possible that there are multiple empty keys in a single object-- all key names in an object are unique. Therefore there can be a maximum of one key per object that is an empty string. If you tried to set a second empty key, it would just replace the first. – Brian Rogers Mar 26 '21 at 19:30