从单独的javascript文件将数据导入数组

时间:2021-02-18 13:32:19

So I have a huge javascript file that is named locationsarray.js. I want to however call this file into this code

所以我有一个名为locationsarray.js的巨大javascript文件。但我想将此文件称为此代码

var myStringArray = ["Hello","World"];

var arrayLength = myStringArray.length;

for (var i = 0; i < arrayLength; i++) {
  //Do something
}

I'm not sure how to get that file into this array. Lastly I need to find a way to output the data within the file into html with new google.maps.LatLng() so that it would plot the points on the map. I'm sorry if this is vague but that's as far as my understanding goes. Please help!

我不知道如何将该文件放入此数组中。最后,我需要找到一种方法,使用新的google.maps.LatLng()将文件中的数据输出到html中,以便绘制地图上的点。如果这很模糊,我很抱歉,但就我的理解而言。请帮忙!

The code for the outside javascript file is structured so:

外部javascript文件的代码结构如下:

 var lsz = 10090;

var CountryTerritory = Array([lsz]);
var Region = Array([lsz]);
var City = Array([lsz]);
var Clicks = Array([lsz]);

CountryTerritory[0] = "United States";
Region[0] = "Florida";
City[0] = "Lauderdale-by-the-Sea";
Clicks[0] = "1";

CountryTerritory[1] = "United States";
Region[1] = "Florida";
City[1] = "Lake Lorraine";
Clicks[1] = "1";

CountryTerritory[2] = "United States";
Region[2] = "Florida";
City[2] = "Palmetto Estates";
Clicks[2] = "1";

1 个解决方案

#1


0  

In you HTML, include both scripts one after the other, starting with the outer:

在你的HTML中,一个接一个地包含两个脚本,从外部开始:

<html>
<head>
    <script type="text/javascript" src="./outerScript"></script>
    <script type="text/javascript" src="./innerScript"></script>
    ...
</head>
<body>
    ...

This will make them use the same scope, so if the first script has var arr = []

这将使它们使用相同的范围,因此如果第一个脚本有var arr = []

You can use arr in the second.

你可以在第二个使用arr。

#1


0  

In you HTML, include both scripts one after the other, starting with the outer:

在你的HTML中,一个接一个地包含两个脚本,从外部开始:

<html>
<head>
    <script type="text/javascript" src="./outerScript"></script>
    <script type="text/javascript" src="./innerScript"></script>
    ...
</head>
<body>
    ...

This will make them use the same scope, so if the first script has var arr = []

这将使它们使用相同的范围,因此如果第一个脚本有var arr = []

You can use arr in the second.

你可以在第二个使用arr。