For loop through Array only shows last value
Change your for
loop:
for (i = 0; i <= (n-1); i++) {
var list = names[i];
var myList = document.getElementById("list");
myList.innerHTML += "<li class='list-group-item' id='listItem'>"+ list + "</li>" + "<br />";
}
Use +=
instead of =
. Other than that, your code looks fine.
For loop only shows last value in array
You are passing a single-element array several times instead of passing a single collection of coordinates.
Try creating a method of
indexToFeature(index) {
const {longitude, latitude, userName, dateTimeCaptured} = index;
return {
"type": "Feature",
"properties": {
'description': "Dispatcher: " + userName + "\n" + "\Lng/Lat\:" + longitude + " / " + latitude + "\n" + "\StartTime\: " + dateTimeCaptured
},
"geometry": {
"type": "Point",
"coordinates": [longitude, latitude, userName, dateTimeCaptured]
}
};
}
Then your main body can simply be
this.map.getSource('data-source').setData({
"type": "FeatureCollection",
"features": this.overwatchTargets.map(indexToFeature)
});
to call setData
once, converting the entire array of overwatchTargets
into an array of features.
In forEach loop, only last value is shown
I think you should declare new XMLHttpRequest();
in each every forEach iteration:
first10.forEach(objs => {
/*HERE*/ let object = new XMLHttpRequest();
object.open('GET', `https://collectionapi.metmuseum.org/public/collection/v1/objects/${objs}`, true);
otherwise you're re-assigning the new calls for the same object so you get the last one only.
Related Topics
How to Download a File Without Using ≪A≫ Element With Download Attribute or a Server
Intercept a Form Submit in JavaScript and Prevent Normal Submission
Alternative For Deprecated Svg Pathseglist
Programmatically Trigger "Select File" Dialog Box
Get Json Data from External Url and Display It in a Div as Plain Text
Add Svg Element to Existing Svg Using Dom
Force Dom Redraw/Refresh on Chrome/Mac
How to Set Font Size Based on Container Size
Parsing CSS in JavaScript/Jquery
How to Change Style of Iframe Content Cross-Domain
How to Implement Dom Data Binding in JavaScript
How to Use Sockets in JavaScript\Html
Programmatically Selecting Partial Text in an Input Field
How to Detect Which One of the Defined Font Was Used in a Web Page
How to Automatically Reload a Web Page At a Certain Time
How to Include CSS and Js Files Via Https When Needed
How to Dynamically Create CSS Class in JavaScript and Apply
Instead of Using Prefixes I Want to Ask Site Visitors to Upgrade Their Browser