iteratively adding to an array of objects in Javascript
I am trying to create an object iteratively with the following structure:

        var series = {
            data: [{
                name:  'some text',
                y: 0
            },
            {
                name:  'some other text',
                y: 1
            }]
        }

Below is my code so far:

    var series = {
        data: []	
    };

    var datatemp = {
        y: '',
        name: ''
    };

    for (var i=0; i<10; i++) {
        datatemp.y = i;
        datatemp.name = "namelabel"+i;
        series.data.push(datatemp);
    }

But what I am getting is the final values of series.data[i].y and series.data[i].name in all elements of the array, rather than what I expect, which is different values as the counter i iterates.  I would appreciate your guidance on what I am doing wrong.  Thanks in advance!



iteratively adding to an array of objects in Javascript
===

I am trying to create an object iteratively with the following structure:

        var series = {
            data: [{
                name:  'some text',
                y: 0
            },
            {
                name:  'some other text',
                y: 1
            }]
        }

Below is my code so far:

    var series = {
        data: []	
    };

    var datatemp = {
        y: '',
        name: ''
    };

    for (var i=0; i<10; i++) {
        datatemp.y = i;
        datatemp.name = "namelabel"+i;
        series.data.push(datatemp);
    }

But what I am getting is the final values of series.data[i].y and series.data[i].name in all elements of the array, rather than what I expect, which is different values as the counter i iterates.  I would appreciate your guidance on what I am doing wrong.  Thanks in advance!


