小黑小波比.判断字段是否存在和字段值是否为空问题
2014-11-03 11:15
369 查看
1.判断字段是否存在。如果字段存在。才可以赋值,否则报错字段未定义
var a =1;
输入:a||2
返回 1
当输入:b||2
返回:1
报错信息:b未定义。所以要判断b定义了。先if(b) 如果定义了返回true 否则false
ReferenceError: b is not defined
at repl:1:2
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.emit (events.js:98:17)
at emitKey (readline.js:1095:12)
2.当字段是一个数组,如果字段存在,子数组也存在。才可以给字数组中的字段赋值
var a ={"a1":1}
当输入:a.a1||3
返回:1
当输入a.a2||3
返回:3
当输入a.a2.b1||3
返回: b1未定义,所以要判断a2是否存在
报错信息:
TypeError: Cannot read property 'b1' of undefined
at repl:1:6
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.emit (events.js:98:17)
at emitKey (readline.js:1095:12)
var a =1;
输入:a||2
返回 1
当输入:b||2
返回:1
报错信息:b未定义。所以要判断b定义了。先if(b) 如果定义了返回true 否则false
ReferenceError: b is not defined
at repl:1:2
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.emit (events.js:98:17)
at emitKey (readline.js:1095:12)
2.当字段是一个数组,如果字段存在,子数组也存在。才可以给字数组中的字段赋值
var a ={"a1":1}
当输入:a.a1||3
返回:1
当输入a.a2||3
返回:3
当输入a.a2.b1||3
返回: b1未定义,所以要判断a2是否存在
报错信息:
TypeError: Cannot read property 'b1' of undefined
at repl:1:6
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.emit (events.js:98:17)
at emitKey (readline.js:1095:12)
相关文章推荐
- 判断表中某一字段是否存在并删除
- 如何判断一个已知的表中是否存在某个字段,如果不存在就创建它.
- 判断单链表是否存在环,判断两个链表是否相交问题详解
- 判断单链表是否存在环,判断两个链表是否相交问题详解
- 判断数据库、表和字段是否存在
- oracle 基础和管理 如何判断某个表中是否存在某个字段?
- 判断单链表是否存在环,判断两个链表是否相交问题详解
- 判断一个表中是否存在某个字段 及 判断数据库中是否有某个
- 判断单链表是否存在环,判断两个链表是否相交问题详解(转载)
- Sql Server 添加删除字段判断表或字段是否存在得到字段描述
- 用Sql添加删除字段,判断字段是否存在的方法
- sql判断表、字段是否存在和增加字段示例
- 用Sql添加删除字段,判断字段是否存在的方法
- 判断表中字段是否存在并添加
- 判断单链表是否存在环,判断两个链表是否相交问题详解
- 问题总结:判断MS SQLSERVER临时表是否存在
- 如何判断一个已知的表中是否存在某个字段,如果不存在就创建它.
- 如何用SQL 语法判断,某一字段在表中是否存在?
- 判断单链表是否存在环,判断两个链表是否相交问题详解
- 判断单链表是否存在环,判断两个链表是否相交问题详解