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...

3 thoughts on “Delete an item form object and delete "null"”

  1. You can use several methods to remove item(s) from an Array:

    someArray.shift(); // first element removed
    someArray = someArray.slice(1); // first element removed
    someArray.splice(0, 1); // first element removed
    someArray.pop(); // last element removed
    someArray = someArray.slice(0, a.length - 1); // last element removed
    someArray.length = someArray.length - 1; // last element removed

    If you want to remove element at position x, use:

    someArray.splice(x, 1);

    in your case

    obj['features'].splice(1, 2);
  2. It’s because you are not removing it from an object, you should be removing it from an array.
    You should do something in the lines of: obj['features'].splice(1, 2);


Leave a Comment