M
M
Medvedoc2021-07-20 21:58:35
JavaScript
Medvedoc, 2021-07-20 21:58:35

How to take out a javascript array into external json and then connect it?

Please tell me how to transfer the javascript array of one file to an external json or ini file, and then connect it to the first file and output it. There can be several arrays.

const aaa = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
const bbb = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-07-20
@sergiks

One array can be placed in a json file like this:
array.json Several like this: dictionary.json And fetch it asynchronously with fetch :["January","February"]
{"aaa":["January","February"],"bbb":["Jan","Feb"]}

fetch('/data/dictionary.json') // URL json-файла
.then((r) => r.json())
.then((dict) => {
  console.log(dict.aaa[1]); // "February"
})
.catch((err) => console.error(err))
;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question