I would like to read geographic data (logitude/latitude) from two sources into one Javascript array. I created an javascript object with an array to hold this data
This is my object definition:
var GeoObject = {
"info": [ ]
};
When reading the two sources of data, if the key RecordId already exists in an array, then append new array elements (lat&lon) to existing GeoObject, otherwise add a new array record.
for instance, if the RecordId 99999 does not already exist then add array (like an SQL add)
GeoObject.info.push(
{ "RecordId": "99999" , "Bing_long": -75.0000, "Bing_lat": 41.0000 } )
if record 99999 already exists, then append new data to existing array (like an SQL update).
GeoObject.info.update???(
{ "RecordId": "99999" , "Google_long": -75.0001, "Google_lat": 41.0001 } )
When the application is finished, each array in the object should have five array elements including the RecordId. Examples:
[ "RecordId": "88888" , "Bing_long": -74.0000, "Bing_lat": 40.0001, "Google_long": -74.0001, "Bing_long": -70.0001 ]
[ "RecordId": "99999" , "Bing_long": -75.0000, "Bing_lat": 41.0001, "Google_long": -75.0001, "Bing_long": -75.0001 ]
I hope that I am clear. This pretty new and a bit complex for me.
Maybe the object definition is not ideal for this case.
[info: {recordId1 => {data1}, recordId2 => {data2}}]
, "push or update" is then justinfo[recId] = blahblah
. To keep it the current format will require a secondary DS or iterating each time (to filter or to mutate), which is not necessarily bad.