如何避免在未定义的变量上读取属性时引发TypeError?

2026-04-02 12:311阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计449个文字,预计阅读时间需要2分钟。

如何避免在未定义的变量上读取属性时引发TypeError?

在P5.js中,加载CSV文件时遇到错误通常是因为CSV文件中的数据格式不正确或读取函数使用不当。以下是对原文的简化版本:

我在P5.js中尝试从.csv文件中加载数据,但不断收到错误信息:无法读取未定义的`arr`属性。

HelloImtryingtoloaddatafromarowina.csvfileonP5JSandIkeepgettingtheerrormessage

Hello I'm trying to load data from a row in a .csv file on P5JS and I keep getting the error message Uncaught TypeError: Cannot read property 'arr' of undefined. Does anyone know why I may be getting this? I have check to make sure there is nothing wrong with my .csv file.

您好我正在尝试从P5JS上的.csv文件中的一行加载数据,并且我一直收到错误消息Uncaught TypeError:无法读取未定义的属性'arr'。有谁知道为什么我会得到这个?我检查以确保我的.csv文件没有任何问题。

var table;var travel = [];function preload() { table = loadTable("data/travel.csv", "csv", "header");}function setup() { createCanvas(400,400); textSize(24); travel = table.getRow(1).arr;}function draw(){ background(255); translate(0,height/1); for(var i = 1; i

1 个解决方案

#1

0

I ran your script with my own csv file and it worked as expected. So, I suspect the problem is in your file. You should start by trying the same code with a different csv file (grabbed from the internet or wherever).

我用自己的csv文件运行你的脚本,它按预期工作。所以,我怀疑问题出在您的档案中。您应该首先尝试使用不同的csv文件(从互联网或任何地方抓取)相同的代码。

如何避免在未定义的变量上读取属性时引发TypeError?

However, I did some searching around and have found a couple of issues noted with load--() P5 functions and the preload() function. If you're still having no luck with this after replacing the csv file, I would try rewriting the script with a callback function rather than using the preload() function. Hope this helps.

但是,我做了一些搜索并发现了一些注意事项,包括load - ()P5函数和preload()函数。如果你在更换csv文件后仍然没有运气,我会尝试使用回调函数而不是使用preload()函数重写脚本。希望这可以帮助。

本文共计449个文字,预计阅读时间需要2分钟。

如何避免在未定义的变量上读取属性时引发TypeError?

在P5.js中,加载CSV文件时遇到错误通常是因为CSV文件中的数据格式不正确或读取函数使用不当。以下是对原文的简化版本:

我在P5.js中尝试从.csv文件中加载数据,但不断收到错误信息:无法读取未定义的`arr`属性。

HelloImtryingtoloaddatafromarowina.csvfileonP5JSandIkeepgettingtheerrormessage

Hello I'm trying to load data from a row in a .csv file on P5JS and I keep getting the error message Uncaught TypeError: Cannot read property 'arr' of undefined. Does anyone know why I may be getting this? I have check to make sure there is nothing wrong with my .csv file.

您好我正在尝试从P5JS上的.csv文件中的一行加载数据,并且我一直收到错误消息Uncaught TypeError:无法读取未定义的属性'arr'。有谁知道为什么我会得到这个?我检查以确保我的.csv文件没有任何问题。

var table;var travel = [];function preload() { table = loadTable("data/travel.csv", "csv", "header");}function setup() { createCanvas(400,400); textSize(24); travel = table.getRow(1).arr;}function draw(){ background(255); translate(0,height/1); for(var i = 1; i

1 个解决方案

#1

0

I ran your script with my own csv file and it worked as expected. So, I suspect the problem is in your file. You should start by trying the same code with a different csv file (grabbed from the internet or wherever).

我用自己的csv文件运行你的脚本,它按预期工作。所以,我怀疑问题出在您的档案中。您应该首先尝试使用不同的csv文件(从互联网或任何地方抓取)相同的代码。

如何避免在未定义的变量上读取属性时引发TypeError?

However, I did some searching around and have found a couple of issues noted with load--() P5 functions and the preload() function. If you're still having no luck with this after replacing the csv file, I would try rewriting the script with a callback function rather than using the preload() function. Hope this helps.

但是,我做了一些搜索并发现了一些注意事项,包括load - ()P5函数和preload()函数。如果你在更换csv文件后仍然没有运气,我会尝试使用回调函数而不是使用preload()函数重写脚本。希望这可以帮助。