错误:未捕获语法错误:意外的令牌[
ERROR: Uncaught SyntaxError: Unexpected token [
我收到了这个奇怪的错误。
Uncaught SyntaxError: Unexpected token [
我不知道为什么会出现这个错误。
有人能告诉我为什么会出现这个错误以及如何解决吗?
sortedArray.push({filteredKeys[i]:_analyzedDataSet[filteredKeys[i]]});
此错误发生在上面的这一行。
console.log("filteredKeys[i]:%s", filteredKeys[i]);
不过,上面的这一行运行良好。
console.log("_analyzedDataSet[filteredKeys[i]]:%s", _analyzedDataSet[filteredKeys[i]]);
此外,上面这条线也很好用。
var filteredKeys = [];
filteredKeys = sortThis(_analyzedDataSet);
var sortedArray = [];
for (var i = 0; i < filteredKeys.length; i++){
//This doesn't cause an error.
console.log("filteredKeys[i]:%s", filteredKeys[i]);
//This doesn't cause an error as well.
console.log("_analyzedDataSet[filteredKeys[i]]:%s", _analyzedDataSet[filteredKeys[i]]);
//But, this cause an error!!
sortedArray.push({filteredKeys[i]:_analyzedDataSet[filteredKeys[i]]});
}
使用对象文字表示法时,不能向对象添加动态键。首先创建对象,然后使用数组符号添加密钥
var newObj = {};
newObj[filteredKeys[i]] = _analyzedDataSet[filteredKeys[i]];
sortedArray.push(newObj);
相关文章:
- 铬:“;未捕获的语法错误:意外的标记:"
- Javascript未捕获语法错误意外的标识符错误
- 未捕获的语法错误:意外的标记{
- "未捕获的语法错误:意外的标记}"
- eslint:“;分析错误:意外的“”标记;
- 未捕获的语法错误:意外的令牌,
- "未捕获的语法错误:意外的标记"角度JS
- "未捕获的语法错误:意外的标记<"当尝试使用谷歌'核心报告API
- NodeJS用Multer上传图片;错误:意外字段“”;
- 在一个函数中,我有一个未捕获的语法错误:意外的标记else
- data.php:1未捕获的语法错误:意外的令牌:
- 未捕获的语法错误:意外的令牌非法?看起来不错
- 未捕获的语法错误:意外的标记<在yii
- AngularJS $http GET 请求到本地 JSON 文件返回语法错误:意外令牌]
- 未捕获的语法错误:意外的令牌 = (Chrome)
- Sencha 2.0 和 Codeigniter RESTful API 生成未捕获的语法错误:意外令牌:
- “语法错误:意外的令牌)”在 javascript 调用中,当 eval(value) 为空时
- HTML 无法识别我要求它运行的 javascript 文件,语法错误:意外的令牌“<”(匿名函数)script.js:
- 未捕获的语法错误:意外的令牌 if
- 使用 JSON.parse 将字符串(变量)转换为对象,错误意外标记