user160820
user160820

Reputation: 15220

how may I access the option values withing an object

I have an object which looks like

    options = {
        offers : $$("div.sonan"),
        prev :   offers[0],
        next :  offers[1]
    }

where the property prev represent the first element of offers array and next represent the second element of offers array.

How may I use offers property within the options object

Upvotes: 0

Views: 51

Answers (2)

vaibhav
vaibhav

Reputation: 550

I see that you are defining the array inside the object definition and using that array to fetch elements to define other properties of the options object. this approach won't work because while parsing the options object first, javascript doesn't know what is offers that is offfers is undefined unless the options object gets parsed.

you can see the below written code for more help.

// define the object
var offs = [1,2,3];
var options = {
    offers : offs,
    prev :   offs[0],
    next :  offs[1]
};
//fetch values from object
options.offers;   // should give u [1,2,3]

Upvotes: 1

GeekMasher
GeekMasher

Reputation: 1086

Try this.

document.write(option[1])

Change the number at the end to change objects.

option : array name.

offers : object 0.

prev : object 1.

next : object 2.

Upvotes: 0

Related Questions