客观的
我想制作这个程序,以便它可以从文本文件中读取数据并将数据存储到Array of Objects.
下面显示的格式是该文本文件将采用的格式,如果可能的话,应修剪逗号后面的空格,但不是完整的字符串。
因此,当该程序运行时,它将把内容推送到一个数组中,该数组稍后可以在程序中用作array.map().
示例文本文件
//file.txt (Note: The main file will always be in this exact format)
John Doe, 01/30/2000, This is the Address, Los Angeles, CA, 70077
Jane Doe, 01/30/2000, This is the Address, Los Angeles, CA, 70077
Arlong Doe, 01/30/2000, This is the Address, Los Angeles, CA, 70077
Mark Doe, 01/30/2000, This is the Address, Los Angeles, CA, 70077
Bill Doe, 01/30/2000, This is the Address, Los Angeles, CA, 70077
// format: [ firstname lastname, date of birth (MM/DD/YYYY), Address, City, State, Zip]
期望输出
array = [
{
firstname: "John",
lastname: "Doe",
dob: '01/30/2000',
address: 'This is the Address',
city: "Los Angeles",
state: "CA",
zip: "70077"
},
{
firstname: "Jane",
lastname: "Doe",
dob: '01/30/2000',
address: 'This is the Address',
city: "Los Angeles",
state: "CA",
zip: "70077"
},
{
firstname: "Arlong",
lastname: "Doe",
dob: '01/30/2000',
address: 'This is the Address',
city: "Los Angeles",
state: "CA",
zip: "70077"
}
] //and so on
慕容森
相关分类