Given this code:
<script type="text/javascript">
var arr = [];
var names = [{name : 'George'}, {name : 'Ringo'}, {name : 'Paul'}, {name : 'John'}];
var surnames = [{surname : 'Harrison'}, {surname : 'Starr'}, {surname : 'McCartney'}, {surname : 'Lennon'}];
for (i = 0; i < names.length; i++) {
arr['firstname'] = names[i];
for (j = 0; j < surnames.length; j++) {
arr['firstname']['surname'] = surnames[j];
arr['firstname']['surname']['index'] = i;
console.log(arr);
}
}
</script>
When run, output in the inner loop would only show the last value of surnames array(Lennon) and i(3) on all entries. Output I want to achieve is for each name, surnames will be distributed to all firstnames (eg. John Harrison, John Starr, etc.) and index(i) will increment from 0 to 3. Thanks.
arr['firstname']as it is.