0

I am declaring an array as such

var positions = [];

or

var positions = new array();

either way works

Later in the script a value is added as such

positions[0].top = 0;

Everything is fine in every browser except ie7 gets this error

Error: Unable to set value of the property 'top': object is null or undefined

Is there another way that I should populate the arra in ie7?

2 Answers 2

1

You want the javascript function push(). You should be doing it like this across the board.

  var positions = ["something", "somethign else"];
  positions.push("something new");

.top is a property of most dom elements I believe, but not appropriate for this array.

Sign up to request clarification or add additional context in comments.

Comments

0

You're trying to add an object value instead of pushing to an array. If you're trying to use an array, then you'll need to use .push():

var positions = [];
    positions.push(value);
    positions.push(value2);

So, in the code above, value will be available at positions[0] and value2 will be available at positions[1].

However, if you're trying to create an object that you can access like so:

position.top;
position.bottom;
etc.

Then you'll need to instead create an object:

var positions = {};
    positions.top = 0;
    positions.bottom = 20;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.