ดูสิ่งมีกุญแจจาวาสคริปต์

รหัสตัวอย่าง

13
0

วิธีตรวจสอบว่าสิ่งมีกุญแจจาวาสคริปต์

myObj.hasOwnProperty('key') // it checks object for particular key and not on prototype   
4
0

typescript ตรวจสอบว่าสิ่งมีกุญแจ

if ('key' in myObj)
2
0

ดูสิ่งมีกุญแจจาวาสคริปต์

Object.prototype.hasOwnProperty()
1
0

จาวาสคริปต์ถ้าสิ่งมีกุญแจ

if('key' in object)
1
0

จาวาสคริปต์โปรดตรวจสอบว่ากุญแจอยู่ในวัตถุ

"key" in obj // true, regardless of the actual value

If you want to check if a key doesn't exist, remember to use parenthesis:
!("key" in obj) // true if "key" doesn't exist in object
!"key" in obj   // ERROR!  Equivalent to "false in obj"

Or, if you want to particularly test for properties of the object instance (and not inherited properties), use hasOwnProperty:
obj.hasOwnProperty("key") // true
-2
0

js สิ่งมีกุญแจ

if ('key' in myObj)
// better
if (!myObj.hasOwnProperty('key'))

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังหน้ากับตัวอย่างอยู่ในหมวดหมู่