'remove element from array without reindex [duplicate]

I have this code to add elements to an array and remove one element.

var test = []

test.push({
    bezeichnung: "test_1"
});
test.push({
    bezeichnung: "test_2"
});
test.push({
    bezeichnung: "test_3"
});



// Element aus Array entfernen
test.splice(1, 1);
console.log(test)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

My console log:

Array [ {…}, {…} ]

0: Object { bezeichnung: "test_1" }
1: Object { bezeichnung: "test_2" } // was removed
1: Object { bezeichnung: "test_3" }

But how can I realize, that the "key" from test 3 will not changed? It should be 2 instead 1. Is there a way?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source