Generally, businesses will have the need to add object attributes to arrays.
Here are several common methods of adding objects for your reference:
1. The most common method: push (add at the end)
Business scene
arr =[{'num':1},{'num':2},{'num':3}];
newArr = arr.push({'num':4})
console.log(arr)
result:
2. unshift (header addition)
arr =[{'num':3},{'num':4},{'num':5}];
newArr = arr.unshift({'num':2})
console.log(arr)
result:
3. Use the splice method to insert, such as inserting an object at index 1
arr =[{'num':1},{'num':3},{'num':4}];
arr.splice(1, 0, {'id': 2})
console.log(arr)
result