Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
属性在尝试访问javascript对象的属性时未定义_Javascript_Object_Properties_Undefined - Fatal编程技术网

属性在尝试访问javascript对象的属性时未定义

属性在尝试访问javascript对象的属性时未定义,javascript,object,properties,undefined,Javascript,Object,Properties,Undefined,我被这个问题弄得不知所措,弄不明白 我正在解析一个带有5行的示例csv(使用csv解析器nodejs模块),所有4个对象的所有第一个属性都未定义 我在这里打印了对象(obj实例): { 'separator': 'test', cor: 'Esmeralda', tam: [ '40', '40' ], brand: 'test2', ref: '20441', price: '149.00', discount: '', price_final: '149.00',

我被这个问题弄得不知所措,弄不明白

我正在解析一个带有5行的示例csv(使用csv解析器nodejs模块),所有4个对象的所有第一个属性都未定义

我在这里打印了对象(obj实例):

{ 'separator': 'test',
cor: 'Esmeralda',
  tam: [ '40', '40' ],
  brand: 'test2',
  ref: '20441',
  price: '149.00',
  discount: '',
  price_final: '149.00',
  other: '42 e 46 Safira, 38 e 44 agua marina, 36 Quartzo Rosa',
  description: '',
  photo: [ '7894', '7898', '7900', '7823' ] }
在obj上执行JSON.stringify时,结果如下:

{"separator":"test","cor":"Esmeralda","tam":["40","40"],"brand":"test2","ref":"20441","price":"149.0
0","discount":"","price_final":"149.00","other":"42 e 46 Safira, 38 e 44 agua marina, 36 Quartzo Rosa","description":"","photo":["7894","7898","7900","7823"]}
当我使用obj['separator']或obj.separator时,我没有定义,这到底是怎么回事

有什么线索吗

编辑:

这是CSV

separator;cor;tam;brand;ref;price;discount;price_final;other;description;photo
test;Esmeralda;40 e 40;test2;20441;149,00;;149,00 €;42 e 46 Safira, 38 e 44 agua marina, 36 Quartzo Rosa;;7894, 7898, 7900, 7823
test;Safira ;42 e 46;test2;20441;149,00;;149,00 €;40 Esmeralda, 38 e 44 Água Marinha, 36 Quartzo Rosa;;7908, 7910, 7823
test;Quartzo Rosa;36;test2;20441;149,00;;149,00 €;40 Esmeralda, 42 e 46 Safira, 38 e 44 Água Marinha;;7913, 7901, 7902, 7823,
test;Água Marinha;38 e 44;test2;20441;149,00;;149,00 €;40 Esmeralda, 42 e 46 Safira, 36 Quartzo Rosa;;7907, 7905, 7823,
我在这里读到:

const csv = require('csv-parser')
const fs = require('fs')
const results = [];
const resultsByRef = {};

fs.createReadStream('vestidos_sample.csv')
  .pipe(csv({ separator: ';' }))
  .on('data', (data) => results.push(data))
  .on('end', () => {
      uniformData();


      
  });

function uniformData(){
    for(let line of results){
        console.log(line['separator']);   // >> undefined        
    }
}

使用此csv选项进行管理:

 fs.createReadStream('vestidos_sample.csv')
  .pipe(csv({ skipLines:1,separator: ';', headers: ['separator','cor','tam','brand','ref','price','discount','price_final','other','description','photo'] }))
  .on('data', (data) => results.push(data))
  .on('end', () => {
      uniformData();

  });

JSON.stringify
返回一个字符串,因此
obj['separator']
将不起作用(顺便说一句,请发布代码)是的,我知道,我刚刚做了JSON.stringify来打印obj的实际内容,我正在使用obj['separator'访问属性请提供您如何创建/定义/实例化/获取对象的代码,以及您如何尝试访问该对象。请发布代码,您做错了其他事情请附上代码,顺便说一句,我正在使用windows