Hi all,
I have encountered a strange problem regarding indices. I have a small snippet of example code that shows this problem:
var a = {}; var c = {}; var b = "0"; a[b] = "hello world"; c["0"] = "hello moon"; console.log(a[b],a[0],a["0"]); // output: hello world undefined undefined console.log(c[b],c[0],c["0"]); // output: undefined hello moon hello moon function foo(id) { console.log(id,a[id], c[id]); } foo(b); // output: 0 hello world undefined foo("0"); // output: 0 hello world undefined
I would expect that a[b] and a["0"] would give the same result?
Thanks for all the help so far!
@Alex started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi all,
I have encountered a strange problem regarding indices. I have a small snippet of example code that shows this problem:
I would expect that a[b] and a["0"] would give the same result?
Thanks for all the help so far!