![](/img/trans.png)
[英]How to add new keys and values to a json from a txt file in node.js
[英]Add values to js script from txt or json file
我有關於向 js 腳本添加值的基本問題。 現在我有方法add
來手動添加主題。
patientFolder.add({'ID': [subject]}, 'ID', ['1_1', 'G321', '2_1', '11', '20', '21'])
我想解析.txt 文件並將其寫入patientFolder.add
,如下所示:
patientFolder.add({'ID': [subject]}, 'ID', /tmp/subjects.txt])
subject.txt 的內容:
1_1
G321
2_1
11
20
21
我該如何實施?
按照示例https://www.geeksforgeeks.org/how-to-read-a-local-text-file-using-javascript/從文件中讀取數據
之后,您可以將文件的 output 拆分為 \n。 這會給你一個數組。 您可以將該數組傳遞給您的 PatientFolder.add function。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.