JohnnyQ JohnnyQ - 2 years ago 127
JSON Question

How to JSON.parse and ignore the array indices?

I have this sample string which I want to parse as an Object

const payload = "{\"teamIds\":[584,585,586]}";


However the result automatically adds the indices:

0: 584,
1: 585,
2: 586

How do I get rid of the indices in this case and just keep
as is?


Coming from a PHP background, I thought this one was possible. Nevertheless, thank you for all your help.

Answer Source

You cannot, that's how arrays work, they need to have indexes for values those are automatically set if you don't provide any of yours. That's just how it works, in javascript, you can assign index, but it then becomes a JSON, not an array, but there cannot be a value in an array without index.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download