Here is an example of the array of objects I am working with:
[
{_id: "59b6433532b60cfc0a253cec", description: "", imagepath:
"https://xxx.1", likes: 0, downvotes: 0}
{_id: "59b6433532b60cfc0a253ceb", description: "", imagepath:
"https://xxx.2", likes: 0, downvotes: 0}
{_id: "59b6433532b60cfc0a253cea", description: "", imagepath:
"https://xxx.3", likes: 0, downvotes: 0}
]
As I implement pagination, the array grows by adding another set of 10
objects each time.
My question is, how can I add a new object into the array when it reaches lengths like 20, 40, and so on?
The desired output would be:
[
{_id: "59b6433532b60cfc0a253cec", description: "", imagepath:
"https://xxx.1", likes: 0, downvotes: 0}
{_id: "59b6433532b60cfc0a253ceb", description: "", imagepath:
"https://xxx.2", likes: 0, downvotes: 0}
{_id: "59b6433532b60cfc0a253cea", description: "", imagepath:
"https://xxx.3", likes: 0, downvotes: 0}
... <--- objects count now at 20
{new object 1}
... <--- objects count now at 40
{new object 1} <--- same as above
]