[英]eval typeof is undefined in javascript
I am trying to create JSON object entered into textbox using below code. 我正在尝试使用以下代码创建输入文本框的JSON对象。
colnames is array of columns from table colnames = [DEPTNO,DNAME], colnames是表colnames = [DEPTNO,DNAME]中的列的数组,
I am trying to create JSON object dynamically. 我正在尝试动态创建JSON对象。 eg
例如
tableInsert.DEPTNO = 100; tableInsert.DEPTNO = 100; tableInsert.DNAME= sales;
tableInsert.DNAME =销售;
but when i run it, it always complain console.log (eval ("tableInsert." + col)); 但是当我运行它时,它总是抱怨console.log(eval(“ tableInsert。” + col)); is undefined.
未定义。 Any help..
任何帮助..
document.getElementById("insercols").onclick = function(){
var tableInsert ='';
var colvalue='';
console.log("cols are " + colnames);
for (col of colnames){
colvalue = document.getElementById(col).value;
eval ("tableInsert." + col + " = " + "typeof "+ colvalue);
console.log("tableInsert." + col + " = " + "typeof "+ colvalue);
console.log (eval ("tableInsert." + col));
}
}
define tableinsert as and try again.. 将tableinsert定义为,然后重试。
var tableInsert = {};
tableInsert[col] = typeof colvalue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.