espace

question about concatenation

Recommended Posts

nice way

var l = [];

for (var i=0; i < 2; i++)
{
  l.push( { a : i } );
}

console.log(l[0], l[1]);

in this case, this === window -> better not pollute it, but you can use it on your own object without worries

for (var i=0; i < 2; i++)
{
  this[ 'l' + i ] = { a : i };
}

console.log(this);
console.log(this.l0, this.l1);

nasty way

for (var i=0; i < 2; i++)
{
  eval( 'l' + i + ' = { a : i } ' );
}

console.log(l0, l1);

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.