Background
[wp_ad_camp_1]
Array with different types of data? Weird stuff! Generally, an array is collection of similar items. In Computer Science 101, this means the items are of the same data type. We have an array of integers, boolean values or strings. But in JavaScript, arrays can have elements of different types.
JavaScript Codes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /* arrayWithVariousData: item 1 - 1 item 2 - an array of The Beatles members item 3 - an object with id and name properties */ var arrayWithVariousData = [1, ['Paul', 'Gringo', 'John', 'George'], {'id': 100 ,'name': 'Steve'}]; console.log(arrayWithVariousData[0]); console.log(arrayWithVariousData[1][0]); console.log(arrayWithVariousData[1][1]); console.log(arrayWithVariousData[1][2]); console.log(arrayWithVariousData[1][3]); console.log(arrayWithVariousData[2].id); console.log(arrayWithVariousData[2].name); |
Outputs:
[wp_ad_camp_3]
1 2 3 4 5 6 7 | 1 Paul Gringo John George 100 Steve |