Remove item from json and edit remaining items – nodejs/firebase function

So I’m trying to update a json, after deleting an item using firebase .delete().

This is the json before delete

"data": [
    {
        "position": "3",
        "name": "foo"
    },
    {
        "name": "bar",
        "position": "1"
    },
    {
        "name": "deleteMe",
        "position": "2"
    },
    {
        "name": "somethingElse",
        "position": "4"
    }
]

and this is after:

"data": [
    {
        "position": "3",
        "name": "foo"
    },
    {
        "name": "bar",
        "position": "1"
    },
    {
        "name": "somethingElse",
        "position": "4"
    }
]

now all I have to do is reorder foo and somethingElse items positions from #3 to #2 and #4 to #3. How can I do this?

EDIT: This is the output I want:

"data": [
    {
        "position": "2",
        "name": "foo"
    },
    {
        "name": "bar",
        "position": "1"
    },
    {
        "name": "somethingElse",
        "position": "3"
    }
]

Answer

Use Array.prototype.map

var obj = {
  data: [
    {
      position: "2",
      name: "foo"
    },
    {
      name: "bar",
      position: "1"
    },
    {
      name: "somethingElse",
      position: "3"
    }
  ]
};
var output = 
  obj.data.map((o, i) => {
    o["position"] = "" + (i + 1);
    return o;
  });
console.log(output);