In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to judge whether the object is null in es6". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope that this article "how to judge whether the object is null in es6" can help you solve the problem.
In es6, you can use the "Object.keys ()" method to determine whether an object is null, which returns an array of enumerable attributes of the object itself, with the syntax of "alert (Object.keys). Length = = 0", and if the result is true, the object is null.
This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.
How to judge whether the object is null in es6
Use the Object.keys () method of ES6
The Object.keys () method returns an array of enumerable properties of a given object, and the return value is also an array of property names in the object.
Examples are as follows:
Var data = {}; var arr = Object.keys (data); alert (arr.length = = 0); / / true is the empty object var datas= {aVO1LI BLAR 2}; var aRR = Object.keys (datas); console.log (aRR)-- > ['aplomb']
Among them, it should be noted that:
If data = = null will report an error, you need to make sure the value is not null or undefined
A brief introduction to the Object.keys () method
Pass in an object and return the property name
Var data= {avell 1, Object.keys brew 2); console.log (Object.keys (data)); / / ["a", "b", "c", "d", "e"] Object.keys (data). Map ((key,item) = > {console.log (key,data [key])); / / key= > attribute name data [key] = > attribute value})
Pass in a string and return the index
Var str = 'ab1234';console.log (Object.keys (obj)); / / [0Jing 1jue 2m 3jue 4je 5]
Incoming array returns index
Var arr = ["a", "b", "c"]; console.log (Object.keys (arr)); / / console: ["0", "1", "2"] this is the end of the introduction of "how to determine whether an object is null in es6". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.