The function adds an object to the array and makes it second in the list. But in this case, I clung to the object and I know what his number after creation (5). How to make it so that it is always added second?
const arr = [{
"name": "BMW",
"price": "55 000",
"country": "Germany",
"certificate": "yes"
},
{
"name": "Mercedes-benz",
"price": "63 000",
"country": "Germany",
"certificate": "yes"
},
{
"name": "Mitsubishi",
"price": "93 000",
"constructor": "Bar John",
"door": "3",
"country": "Japan",
},
{
"name": "TOYOTA",
"price": "48 000",
"max_people": "7",
"country": "Japan",
"certificate": "yes"
},
{
"name": "Volkswagen",
"price": "36 000",
"constructor": "Pier Sun",
"country": "Germany",
"certificate": "no"
},
];
function pushArr(arr, item) {
arr.push(item);
arr[5] = [arr[1], arr[1] = arr[5]][0];
}
let newArr = pushArr(arr, {
"name": "Audi",
"price": "89 000",
"constructor": "Adolf Trump",
"country": "Germany",
"certificate": "yes"
});
console.log(arr);