Reputation: 9
var obj = {"":"empty string", "!":"bang", "hello world":"hello world"}
-Fix these lines of code so it works?
Whatever method i've tried, i keep coming up with an undefined property name for "" or an error when calling for !.
I'm very new to coding and am not looking for an answer, maybe just a push in the right direction..So please be gentle and thanks for any help
Upvotes: 0
Views: 72
Reputation: 2469
You must call obj like an Array
console.log( obj [''] ); // "empty string"
console.log( obj ['!'] ); // "bang"
var x='!';
console.log( obj [x] ); // "bang"
Upvotes: 2
Reputation: 28455
As per my understanding you want to retrieve "Empty String"
You can get the information by following
var obj = {"":"empty string", "!":"bang", "hello world":"hello world"}
console.log(obj[""]);
Upvotes: 0