[SOLVED] List with rows cannot be accessed by common JS syntax; '.data'

ok, then

Forget those (they are meta within my debugging)
Let me ask in another way; my values are int’s and not strings -> should I make them strings in order to make it work? (trying it now - just quite contra-intutitve)

Modify the CSV conversion code so that it converts to strings before using the replace function.

Edit: ie:

result += '"' + item[key].toString().replace('\"', """) + '"';

Works (discouraged by the err-msg, though … hard to come to same conclusion as you, if seen for first time - as for me :slight_smile: ) … one has to understand the csv-parsing

Anyways, I have to state:

Reformulating: "ok, get that ‘PC-JS’ === vanilla JS (ES5) " … to “ok, get that ‘PC-JS’ == vanilla JS (ES5)

  • as the surrounding PC-structure still makes it a little different “someScr.prototype.someName = function() {” … etc

That’s the default structure for a class in ES5 (https://www.accelebrate.com/blog/javascript-es6-classes-and-prototype-inheritance-part-1-of-2/)

ok, getting to the most constructive island then; what you are saying is that I should add “ES5” to all my “js” google searches from now on?

Depends on what browsers you are targeting. You can write in ES6 if you want (the linter might complain but you can disable that with a specific comment at the top of the file).

The PlayCanvas engine is written in ES5 but doesn’t stop the developer from using ES6 if they want.

All engine code, the scripts that the developer creates has to run as is in the browser. At most, the PlayCanvas build system will minimise the code and concatenates the scripts into one large one in an order that the developer can define in project settings.

I run through the thought process when I was debugging this as you posted it.

Looking at the error message, it’s saying that replace is not a function of item[key]. Looking at the CSV code, item is an entry of the array of objects that we passed in so item[key] is one of the properties of the object.

Judging from how the replace function is used, it looks like a string replace function.

Test the theory and see what happens when I pass a number instead of string. Crashes.

Looks like an easy fix. Just has to make sure that we convert the value to a string before using the replace function.

result += '"' + item[key].toString().replace('\"', """) + '"';

Test with previous fail case. Looks like it works.

1 Like