Search code examples
javascriptmapboxmapbox-gl

How to import a dataset directly into my javascript code


I would like to know if I could import a dataset directly into my code (javascript), because I want to make a condition for when the user presses a certain function, to display a given dataset.


Solution

  • If you can get your data in String format as JSON array or dictionary you can just use JSON.parse() to create an object from your data in string format. Then use that object for extracting all info for display. Here are some examples

    From w3schools:

    var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
    obj.name // "John"
    obj.age  // 30
    obj.city // "New York"