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. NXP LPC18xx LPC43xx OTP ID Boot

    static LPC_DEVICE_TYPE LPCtypes[] = { { , , , , , , , , , CHIP_VARIANT_NONE }, /* unknown */ // id, ...

  2. 正确识别希捷Backup Plus新睿品1TB正品,杜绝奸商猖獗

    刚刚在百度希捷贴吧发了此贴, 马上被删除, 无奈只能发于个人博客,  望看到的朋友能转载到"合适"位置,让更多的朋友看到. 避免上当. 最近准备买个移动硬盘备份电脑资料,看上了睿品 ...

  3. Delphi2010 RTTI + Attribute 简单实现ORM实例

    1.支持ORM,最基础的两个信息是表的信息和字段信息.这两个信息,如果用Attribute 来辅助,代码更简洁和可读性更好.可以把属性名当做真实字段名,也可以将特性里的属性当成真实姓名,再加上字段标题 ...

  4. Mybatis-Plus 多表联查分页

    原文:https://www.jianshu.com/p/759b6430ed5b 分析 使用的工程,依旧是 spring-boot,关于分页,官网给出了一个单表的 demo,其实多表分页实现原理相同 ...

  5. 美国恐怖故事第七季/全集American Horror Story全迅雷下载

    FX电视台已经续订了<美国恐怖故事>第七季,将于2017年开播,第七季终于确定副标题为<邪教 Cult>.剧集的创造者瑞恩·墨菲与布拉德·法尔查克将再度联手.顺便一说,< ...

  6. JavaScript中的方法、方法引用和参数

    首先,我们来看一段代码,如果觉得不甚明白的,则本文会对你有益: var player = function (e) {             return (function f(m) {      ...

  7. modbus.c

    #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> //#include ...

  8. SVG.js 基础图形绘制整理(二)

    一.折线 var draw = SVG('svg1').size(300, 300); //画折线 //使用字符串点 // var polyline=draw.polyline('0,0 100,50 ...

  9. Promise is rejected: Error: 2 UNKNOWN: error starting container: API error (404): {"message":"network build-blockchain-insurance-app_default not found"}出错的解决方案

    错误描述: docker logs web 现象: > blockchain-for-insurance@2.1.0 serve /app > cross-env NODE_ENV=pro ...

  10. Django创建自定义错误页面400/403/404/500等

    直接参考: https://zhuanlan.zhihu.com/p/38006919 DEBUG =True的话,为开发环境,显示不了404页面.