Reputation: 51
I am trying to carry the array of data from one HTML file to another? is that possible and if so how can I do this? Maybe use
here is an example:
First HTML file
<script>
let tmp = <%- result %>;
let a = ''
for (const i in tmp){
a += tmp[i]['PartitionKey'] + ' ' + tmp[i]['company_name']
}
console.log(a);
export{ a }
</script>
Second HTML file
<script>
import { a } from './client.html'
console.log(a);
</script>
Upvotes: 0
Views: 1187
Reputation: 357
Yes. But you need to use modules. For example, you have two .js files. index.js and index2.js.
Code of index.js
import { a } from './index2.js';
console.log({ a });
Code of index2.js
export const a = 10;
To use modules in js you have to connect index.js to .html page by <script src="index.js" type="module"></script>
And it will only work with http server. To run http server locally you can use this package https://www.npmjs.com/package/http-server
Upvotes: 2