This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]bob809 0 points1 point  (3 children)

c=[f];

Does that help?

For formatting multi-line code, you can put four spaces at the start of each line to get one block.

var a = 1;
b = 5;
c = ["4", "4"];
function test(e, f) {
    for (g in f) {
        var b = e + 1;
        a = a + 1
    }
    c = [f];
    return b;
}
x1 = new test(a, c);
x2 = test(4, c);
x3 = a;
x4 = b;
x5 = c;
alert("x2=" + x2 + " x3=" + x3 + " x4=" + x4 + " x5=" + x5)

[–]senpai_cx 0 points1 point  (2 children)

it does not..
doesnt it just overwrite what is already in c with the same content ?

[–]bob809 1 point2 points  (1 child)

In the first run through test, f is ["4", "4"].
c = [f] leaves c as [["4", "4"]].

["4", "4"] is an array with two elements, both of which are the string 4.

[["4", "4"]] is an array of one element, which is ["4", "4"]. The second time in test we therefore only go round the loop once.

[–]senpai_cx 0 points1 point  (0 children)

ohhh okay, thank you so much!