Doing a project currently using Knockout.JS as my MVVM framework. I'm trying some basic operations such as accessing the values of my particular markersArray object using something simple such as markersArray['Tiong Bahru Station (EWL)']. I understand that I have to use square bracket notation due to the presence of spaces. However, when I console.log this, and further in my code, it has no value.
Code is below:
JS
In scripts.js file:
var stationList = [
{name: "Tiong Bahru Station (EWL)", marker: markersArray['Tiong Bahru
Station (EWL)']}
console.log(markersArray['Tiong Bahru Station (EWL)']); // Returns undefined
In maps.js file:
var markersArray = {};
for (var i = 0; i < markers.length; i ++) {
marker = new google.maps.Marker({
position: markers[i].position,
map: map,
animation: google.maps.Animation.DROP
});
var name = markers[i].name;
markersArray[name] = marker;
}
var markers = [
{name:"Tiong Bahru Station (EWL)", position: {lat:1.28498, lng:103.82283}}
];
I went to check the console.log for my markersArray to ensure that it is built correctly and it is populated correctly. Would appreciate some help in figuring out why I'm not getting any value from just accessing the value using the key.
stationListis an Array you are defining, but there is nomarkersArraydefined, so definingstationListfails. In you updated second snippet there is no Arraymarkersso that fails too. I suggest you make one snippet you hope will work and then the community can advise.