How to create dynamic array for example pairs of data using javascript? i want the exact structure as shown in example data pairs in dynamic array. i tried code below but it seems my array is not correct. could any one help me fix it.Thanks
Note: alert(files.join('\n')); shows [object object] Example of pairs of data to be stored in array
files: [
{'url': 'http://www.somesite.com/1.jpg', 'filename': 'new1.jpg'},
{'url': 'http://www.somesite.com/2.jpg', 'filename': 'new2.jpg'},
{'url': 'http://www.somesite.com/2.jpg', 'filename': 'new3.jpg'},
],
My array creation function:
<script>
var i=1;
files = new Array();
function addtoArray(a,b){
alert("URL:"+a+"\nFileName:"+b);
files[i] = { url: +a, filename: +b };
i++;
alert(files.join('\n'));
};
</script>
<body>
<button onclick="addtoArray('http://www.somesite.com/1.jpg','new1.jpg')">add to array</button>
<button onclick="addtoArray('http://www.somesite.com/2.jpg','new2.jpg')">add to array</button>
Try this.
EDIT: Adding code to display the content