Search code examples
javascriptobjectgeojson

Delete an item form object and delete "null"


I have this object Geojson, when i do an "delete obj['features'][2]" , it left an "null" (look at the end), how can i delete this ? Or there is an another solution ?

{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[4.23,48.17]},"properties":{"id":12,"subject":"Sujet essaicatogrie","duration":3,"dateStart":"2020-11-12T00:00:00+00:00","dateEnd":null,"gratis":true,"category":"Sport_walk","media":"5fadd4e225097948791983.jpg"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.71,47.02]},"properties":{"id":13,"subject":"Marche sur les terrils","duration":2,"dateStart":"2020-11-24T00:00:00+00:00","dateEnd":null,"gratis":true,"category":"Sport_walk","media":"5fb3d3d7061b4566505116.jpg"}},null, <------- this {"type":"Featur...


Solution

  • It's because you are trying use the notation to remove it from an object. In your example you are removing it from an array.

    You should do something in the lines of:

    obj['features'].splice(1, 2);