This question already has answers here:
JavaScript property access: dot notation vs. brackets?
(17 answers)
Closed 8 years ago.
I didn't know that this is possible in JavaScript:
var test = {
"hello world": function(){
console.log('test');
}
};
Of course this is only a theoretical question:
Is there a possible way to call the hello world function other than test["hello world"]()?
Would it be possible to call it with the . operator?
Sorry but if key is has some special character then you cannot call this with '.' operator.
only way to call is bracket notation which you already know
Related
This question already has answers here:
Easy way to turn JavaScript array into comma-separated list?
(22 answers)
Closed 2 years ago.
Code:
let myClassFellows=[ ['Noor',1],['Jawaria',2]];
console.log(myClassFellows[0]);
Below is the output I want to show without the square brackets
What do you mean without square brackets? Like 'Noor', 1?
If so, you need to concatenate it into a string with myClassFellows[0].join(', ').
This question already has answers here:
What is the explanation for these bizarre JavaScript behaviours mentioned in the 'Wat' talk for CodeMash 2012?
(5 answers)
Objects and arrays addition
(4 answers)
Closed 3 years ago.
Why is the result of the expression {}+[] 0?
It appears that the + is treated as a unary operator instead of a normal addition operator. The expression then becomes {}0. Why is this valid JavaScript and why is the result 0? Why is the object literal in the expression ({})+[] treated normally?
Note: I tried searching for a similar question in SO but it doesn't look like searching using symbols works.
This question already has answers here:
What are the different ways of writing an IIFE? What are their use cases?
(2 answers)
What does the exclamation mark do before the function?
(8 answers)
Closed 4 years ago.
I have seen the bitwise operator used in a self calling function, see below example, so I have a simple question, what does it do?
~(function() {
alert("Hello World");
})();
This question already has answers here:
Calling member function of number literal
(3 answers)
Closed 6 years ago.
toString() doesn't work on numeric literal like 5.toString(), but it works on string literal ("str".toString()) or after the numeric literal is assigned to var, like var a = 5;a.toString(). Wondering why it doesn't work for the first case?
You can do this if you wrap it in parenthesis.
(5).toString();
The first dot is the decimal mark. You need a second one to access the property:
5..toString();
This question already has answers here:
How can I access object properties containing special characters?
(2 answers)
Closed 8 years ago.
I have an object which looks like this:
{"response":{"mydata":[{"xxx:id":"8c8b9703-bc87-40d8-b8d7-f71ebff4002a","Description":"Tsameple desc"].....
Now, my question is, How do I access the Id field?
I have tried
$.response.mydata[i].xxx:id
However, this is resulting in an error thanks to the ":" in the key value. Any tips on how I can get the value?
Use the bracket notation :
response.mydata[i]['xxx:id']