how to insert object into beginning of object list, when it has unshift is not a function error?
<p>How to insert object element in object which is list of object ?</p>

<p>I have this tiny piece of code in ReactJS:</p>

<pre><code>var allMessages = this.state.data;
var newMessages = allMessages.unshift([data]); // i suppose it should be unshift if it was an array, but it is an object o_O
this.setState({ data: newMessages });
</code></pre>

<p>Where:
(chrome console output)</p>

<pre><code>&gt; data
Object {id: "12", text: "1234124", date: "2016-04-28 20:00:07", sender: "user", type: "receiver"}
&gt; allMessages
[Array[1], Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
&gt; typeof allMessages
"object"
</code></pre>

<p>How to insert <code>data</code> into beginning of <code>allMessages</code> ?</p>

<p>I have seen this reply <a href="https://stackoverflow.com/questions/8073673/how-can-i-add-new-array-elements-at-the-beginning-of-an-array-in-javascript">How can I add new array elements at the beginning of an array in JavaScript?</a> and it is another case because my <code>allMessages</code> variable is an <code>object</code> not an Array. </p>

<p>I got <code>unshift is not a function</code> when i try to use <code>unshift</code></p>