Push object in the middle of an array object

[
{
“class”: {
“class”: “App”,
“id”: “4459778”,
“time”: “2018-02-06 08:59:09”
},
“user”: {
“name”: “sample1”,
“picture”: “null”
},
“message”: “inside array”
},
{
“class”: {
“class”: “App”,
“id”: “B5B29E5”,
“time”: “2018-02-04 12:05:03”
},
“user”: {
“name”: “array2”,
“picture”: “null”
},
“message”: “sample2”
}
]

i want to add this in the first index of the array:
{
“class”: {
“class”: “App”,
“id”: “B5B29E5”,
“time”: “2018-02-04 12:05:03”
},
“user”: {
“name”: “array2”,
“picture”: “null”
},
“message”: “sample2”
}

how do i do this?

If you want it to be first in the array use unshift.

1 Like