Here is a simple example:
for (i = 1; i < totalRows; i++) {
if(rows[i][10] == null) {
spreadsheet.add({ [i]: { 10: "Added" } });
}
}
why do I get an error "Unexpected token [" here:
spreadsheet.add({ [i] : { 10:
^
I am trying to run the app on nodejs
version v0.10.35
, I cant update it as its a free server provided by OpenShift . It runs fine on my localhost
computer with nodejs v4.4.7
Please advice a workaround for this code, so it could be executed.
Basically what this code does is, it looks in every row if column 10 is empty
, and if its empty, it adds Added
You defining an object property invalidly.
This is the code that will work:
for (i = 1; i < totalRows; i++) {
if(rows[i][10] == null) {
var obj = {};
obj[i] = { 10: "Added" };
spreadsheet.add(obj);
}
}
Check MDN documentation regarding the working with properties: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.