0

I'm looking at this code I am not able to get the value of 'start' in the hash.

 w[l] = w[l] || [];
    w[l].push({
        'gtm.start':
            new Date().getTime(),
        event: 'gtm.js'
    });

I thought I could do:

w[l].start

or

w[l]['start']

But I get undefined errors.

w is passed in as a parameter, and it is a window object.

3
  • 1
    the name of the properly is gtm.start Commented Mar 31, 2016 at 14:41
  • also w[l] is an array Commented Mar 31, 2016 at 14:42
  • what about w[l].gtm.start Commented Mar 31, 2016 at 14:42

2 Answers 2

1

w[l] is an array w[l] = w[l] || [];

Then you push an object to that array w[l].push({ ...

So you can access that object property with w[l][0]['gtm.start'] (assuming that the array is empty when you pushed the object)

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

Comments

1

Working JsBin: https://jsbin.com/zilado/1/edit?js,console

So lets say you start with an empty array at w[1], w itself is also an array.

You then push an Object to that array so w[1] is an array with an Object in it, that object has what your looking for, and you can access it like so:

var w = [];
w[1] = [];


w[1].push({'gtm.start': new Date().getTime()});

console.log(w[1][0]['gtm.start'])

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.