In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how es6 judges whether the object key exists or not, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.
Judgment method: 1. Use "Object.keys(obj)" statement to return an array containing all keys of obj object;2. Use "Array.includes("key value ")" statement to judge whether the specified value exists in the key array. If the return value is true, the specified key exists in the object, otherwise it does not exist.
Operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.
es6 Determine whether the object key exists
Implementation ideas:
Use the Object.keys() method to get all keys of the object. The return value is an array.
Use the includes() method to determine whether a key array contains a specified key value
Implementation code: Determine whether key "a" exists in object obj
var obj = { a:"little white." b:"black"; c:"big yellow"};var keys=Object.keys(obj);console.log(keys);if(keys.includes("a")){ console.log("key exists in obj object");}else{ console.log("key does not exist in obj object");}
Thank you for reading this article carefully. I hope that the article "es6 how to judge whether the object key exists" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support you more, pay attention to the industry information channel, and more relevant knowledge is waiting for you to learn!
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.