How do I create an array from a JSON data without repeating the values? : <p>I retrieved a JSON from an API that looks like this:</p>

<pre><code>{
    "status": "success",
    "response": [
        {
            "id": 1,
            "name": "SEA BUSES",
            "image": null
        },
        {
            "id": 2,
            "name": "BEN BUSES",
            "image": null
        },
        {
            "id": 3,
            "name": "CAPE BUSES",
            "image": null
        }
    ]
}
</code></pre>

<p>I want to create an array of the IDs in this form ids = [1,2,3] </p>

<p>this is my javascript:</p>

<pre><code>companyid = response.data.response
        var ids = [];
        for (var i = 0; i &lt; companyid.length; i++){
           ids.push(companyid[i].id)
           console.log(ids)
        }
</code></pre>

<p>but the output is not what I expected.
It shows this way:</p>

<pre><code>[ 1 ]
[ 1, 2 ]
[ 1, 2, 3 ]
</code></pre>

<p>Any help please?</p>
