dor
dor

Reputation: 158

generating array of object without keys

I have an array of objects like so:

[
 0:'some value'
 1:'some value'
 3:'some value'
]

and what i want is a nice array of objects without keys for an editabale select like so:

       [
          {value: 1, text: 'Active'},
          {value: 2, text: 'Blocked'},
          {value: 3, text: 'Deleted'}
       ]

i have tried looping and assigning, but i am getting the same result. how can i achieve this array:

cities.push({value:value, text:value});

Upvotes: 1

Views: 1728

Answers (1)

Nate
Nate

Reputation: 420

Your initial 'array of objects' doesn't make sense...do you mean those are the properties of a given single object?

If so, what you need to do is use a for in loop to loop over the objects properties, e.g.

for (var property in obj) {
  cities.push({value: property, text: obj[property]});
}

Upvotes: 1

Related Questions