OliverJ90
OliverJ90

Reputation: 1311

Using index to pull items from an object

If I have an object with items named and ending in sequential numbers:

var theobject = { item1:, item2:, item3:, ...etc }

this method of extracting the objects and used in a for loop does not seem to work. Should this work provided the rest of the function is correct?

theobject.item+i

Upvotes: 0

Views: 36

Answers (1)

Nish
Nish

Reputation: 1736

You can do something like theobject['item'+i]. But you can do something better using jquery foreach so that you can iterate over keys.

Upvotes: 2

Related Questions