Pushing elements to an array in Jade

I am trying to create an array in Jade and then loop through another and create a new array from it. I am doing something like:

         .metadata4
          - var prepopulate = []
          - if (entry.artist_ids)
            - for (var artist in entry.artist_ids)
              - var name = entry.artist_ids[artist]
              - prepopulate.push({id: name, name: name})
        input(type='text', class='token-input', data-url="/query", data-pre=prepopulate)

All this works awesome. However, it seems to add an extra element onto the end of the list (like its pushing the function push to the array or something). Anyone know why this may be?

I am not sure why this is happening and also didn't test it. as a workaround, what you can do is, declare a new var i = 0; and then increment it inside the for. and put prepopulate.push({id: name, name: name}) inside an if statement, like if(i < entry.artist_ids.length - 1){...push...}

I cannot reproduce this behavior, using the following data

entry = { "artist_ids": {1: "hello", 2:"robert"} } 

I get the following data-pre:

[{"id":"hello","name":"hello"},{"id":"robert","name":"robert"}]

which is exactly what you wrote (although I suspect you wanted to replace id's name value with artist)

Maybe you could post your entry object?