Sometime you need to check one prop exists on the object and value should not be ´null´ or ´undefined´.

One problem people may occur with:

const {get} = require('lodash')
const obj = {a: }
const existing = typeof get(obj, 'a') !== undefined // true

Here we missed if the value of 'a' is null:

const obj = {a: null}
const existing = typeof get(obj, 'a') !== undefined // false, because typeof null === 'object'

To solve the problem we can actully using

get(obj, 'a') != null // double equals null checks both null and undefined cases

[Javascript] Check both prop exists and value is valid的更多相关文章

  1. [Javascript] Keyword 'in' to check prop exists on Object

    function addTo80(n ) { + n; } function memoizedAddTo80 (fn) { let cache = {}; return (n) => { /*k ...

  2. loadrunner录制时弹出invalid application path!please check if application exists对话框

    问题:oadrunner录制时弹出invalid application path!please check if application exists对话框 原因:IE浏览器地址不对,需要手动重新选 ...

  3. [转载]—Health Check Reports Problem: Dependency$ p_timestamp mismatch for VALID objects (文档 ID 781959.1)

    Health Check Reports Problem: Dependency$ p_timestamp mismatch for VALID objects (文档 ID 781959.1) AP ...

  4. check process id exists

    kill -0 pid sending the signal 0 to a given PID just checks if any process with the given PID is run ...

  5. Check if KeyValuePair exists with LINQ's FirstOrDefault

    http://stackoverflow.com/questions/793897/check-if-keyvaluepair-exists-with-linqs-firstordefault 问题: ...

  6. javascript (0, obj.prop)()的用法

    我第一次看到这种奇怪的用法是在babel的源码中, 其实它的原理就是使得在prop这个方法里无法获取this, 从而无法对类中的其他变量或方法做操作. obj.prop() 这是一个方法调用, pro ...

  7. [Javascript] Check Promise is Promise

    const isPromise = obj => Boolean(obj) && typeof obj.then === 'function'; This can be a to ...

  8. javascript判断元素存在和判断元素存在于实时的dom中的方法

    今天(周六)下午我在公司加班时不知道要干什么,就打开公司的一个wordpress项目网站,想看下之前自己做的一个网页是否有问题. 打开网站首页,我习惯性的打开了chrome的调试工具,然后鼠标开始滚动 ...

  9. Javascript和Java获取各种form表单信息的简单实例

    大家都知道我们在提交form的时候用了多种input表单.可是不是每一种input表单都是很简单的用Document.getElementById的方式就可以获取到的.有一些组合的form类似于che ...

随机推荐

  1. ICO如此疯狂为哪般?

    编者语: 独角兽一词起源于硅谷,是投资行业,尤其是风险投资业的术语,指的是那些估值超过十亿美元的创业公司.独角兽凤毛麟角,占创业公司总数的0.1%都不到.鑫根资本认为,一个独角兽能达到如此估值,肯定是 ...

  2. javascript UI框架

    http://www.jianshu.com/p/709e8d6c03c9 http://www.cnblogs.com/kingboy2008/p/5261771.html jQuery uiboo ...

  3. Ubuntu14.04LTS下使用eclipse搭建Cocos2d-x的Android环境

    from://http://www.58player.com/blog-2534-94136.html 最近想玩玩游戏制作,于是选择了目前流行的游戏引擎Cocos2d-x,这个东西虽然有Android ...

  4. SpringMVC从Controller跳转到还有一个Controller

    1. 需求背景 需求:spring MVC框架controller间跳转,需重定向.有几种情况:不带參数跳转.带參数拼接url形式跳转,带參数不拼接參数跳转,页面也能显示. 本来以为挺简单的一件事情. ...

  5. Git:常用命令(一)

    取得项目的Git 仓库 从当前目录初始化 git init 初始化后,在当前目录下会出现一个名为.git 的目录,所有Git 需要的数据和资源都存放在这个目录中.不过目前,仅仅是按照既有的结构框架初始 ...

  6. Win8 Metro风格的Web桌面HteOS

    前言     曾经天天折腾ExtJS,折腾累了.近期这段时间開始用jquery来做一些东西,发现还是蛮有意思的.可是做到最后才发现,原来做好设计真的很重要. 上图就是HteOS项目的截图,眼下正在开发 ...

  7. fabric-ca-client

    fabric-ca-client enroll -u http://admin:adminpw@localhost:7054 /root/.fabric-ca-client:总用量 12-rwxr-x ...

  8. [Web 前端] webstorm 快速搭建react项目

    cp from : https://blog.csdn.net/qq_39207948/article/details/79467144 前端新手如何安装webstorm ,初步搭建react项目 下 ...

  9. Binary Search Tree 以及一道 LeetCode 题目

    一道LeetCode题目 今天刷一道LeetCode的题目,要求是这样的: Given a binary search tree and the lowest and highest boundari ...

  10. JavaScript 中的异常处理

    考虑到 JS 中的错误可比服务器端的代码产生的错误要多得多,并且还难以发现及修正,所以 JS 代码必须有异常处理以及全局一场处理. try { //这段代码从上往下运行,其中任何一个语句抛出异常该代码 ...