How to check an object property if the property name is an empty string?

JavaScript object properties can be named with an empty string, for example:

foo = { "" : "bar" } 

Point notation does not seem to be able to name this property. Console output:

 foo. >> "missing name after . operator" 

What would you call a property?

+6
source share
2 answers

Use an empty string as a key with console syntax:

 foo[""] 
+4
source

This can be done using the square brackets. Console output:

 foo[""] >> "bar" 

Documentation

0
source

Source: https://habr.com/ru/post/988348/


All Articles