0

My code :

var listaIDOrdine = new Array();
for (i = 0; i < 10; i++) {
    listaIDOrdine[i] == new CoppiaIDOrdine(1, 1);
    console.log(listaIDOrdine[i]);
}

function CoppiaIDOrdine(id, ordine) {
    this.id = id;
    this.id = ordine;
}

but I get 10 undefined! What is wrong? I expect to have the "couple" of item at every console.log().

Also tried with console.log(listaIDOrdine[i].id); but seems that id is undefined?

1
  • 1
    use = instead of ==, you are comparing instead of assigning. Commented Sep 17, 2012 at 15:30

2 Answers 2

8

You are using == (comparison operator) when you should be using = (assignment operator):

listaIDOrdine[i] = new CoppiaIDOrdine(1, 1);

Also, you could use Array#push instead to add elements to the array:

listaIDOrdine.push(new CoppiaIDOrdine(1, 1));
Sign up to request clarification or add additional context in comments.

1 Comment

I always over complicate my problems. Take a break, drink some water and tell yourself, Think simple.
1

You are doing an equality check instead of an assignment.

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.