← Back to context Comment by idle_zealot 1 day ago Does it count as 0-indexing when your 0 is a floating point number? 5 comments idle_zealot Reply krackers 21 hours ago Actually in JS array indexing is same as property indexing right? So it's actually looking up the string '0', as in arr['0'] idle_zealot 21 hours ago Huh. I always thought that JS objects supported string and number keys separately, like lua. Nope! [Documents]$ cat test.js let testArray = []; testArray[0] = "foo"; testArray["0"] = "bar"; console.log(testArray[0]); console.log(testArray["0"]); [Documents]$ jsc test.js bar bar [Documents]$ nvlled 15 hours ago Lua supports even functions and objects as keys: function f1() end function f2() end local m1 = {} local m2 = {} local obj = { [f1] = 1, [f2] = 2, [m1] = 3, [m2] = 4, } print(obj[f1], obj[f2], obj[m1], obj[m2], obj[{}]) Functions as keys is handy when implementing a quick pub/sub. aidenn0 20 hours ago They do, but strings that are numbers will be reinterpreted as numbers.[edit] let testArray = []; testArray[0] = "foo"; testArray["0"] = "bar"; testArray["00"] = "baz"; console.log(testArray[0]); console.log(testArray["0"]); console.log(testArray["00"]); 1 reply →
krackers 21 hours ago Actually in JS array indexing is same as property indexing right? So it's actually looking up the string '0', as in arr['0'] idle_zealot 21 hours ago Huh. I always thought that JS objects supported string and number keys separately, like lua. Nope! [Documents]$ cat test.js let testArray = []; testArray[0] = "foo"; testArray["0"] = "bar"; console.log(testArray[0]); console.log(testArray["0"]); [Documents]$ jsc test.js bar bar [Documents]$ nvlled 15 hours ago Lua supports even functions and objects as keys: function f1() end function f2() end local m1 = {} local m2 = {} local obj = { [f1] = 1, [f2] = 2, [m1] = 3, [m2] = 4, } print(obj[f1], obj[f2], obj[m1], obj[m2], obj[{}]) Functions as keys is handy when implementing a quick pub/sub. aidenn0 20 hours ago They do, but strings that are numbers will be reinterpreted as numbers.[edit] let testArray = []; testArray[0] = "foo"; testArray["0"] = "bar"; testArray["00"] = "baz"; console.log(testArray[0]); console.log(testArray["0"]); console.log(testArray["00"]); 1 reply →
idle_zealot 21 hours ago Huh. I always thought that JS objects supported string and number keys separately, like lua. Nope! [Documents]$ cat test.js let testArray = []; testArray[0] = "foo"; testArray["0"] = "bar"; console.log(testArray[0]); console.log(testArray["0"]); [Documents]$ jsc test.js bar bar [Documents]$ nvlled 15 hours ago Lua supports even functions and objects as keys: function f1() end function f2() end local m1 = {} local m2 = {} local obj = { [f1] = 1, [f2] = 2, [m1] = 3, [m2] = 4, } print(obj[f1], obj[f2], obj[m1], obj[m2], obj[{}]) Functions as keys is handy when implementing a quick pub/sub. aidenn0 20 hours ago They do, but strings that are numbers will be reinterpreted as numbers.[edit] let testArray = []; testArray[0] = "foo"; testArray["0"] = "bar"; testArray["00"] = "baz"; console.log(testArray[0]); console.log(testArray["0"]); console.log(testArray["00"]); 1 reply →
nvlled 15 hours ago Lua supports even functions and objects as keys: function f1() end function f2() end local m1 = {} local m2 = {} local obj = { [f1] = 1, [f2] = 2, [m1] = 3, [m2] = 4, } print(obj[f1], obj[f2], obj[m1], obj[m2], obj[{}]) Functions as keys is handy when implementing a quick pub/sub.
aidenn0 20 hours ago They do, but strings that are numbers will be reinterpreted as numbers.[edit] let testArray = []; testArray[0] = "foo"; testArray["0"] = "bar"; testArray["00"] = "baz"; console.log(testArray[0]); console.log(testArray["0"]); console.log(testArray["00"]); 1 reply →
Actually in JS array indexing is same as property indexing right? So it's actually looking up the string '0', as in arr['0']
Huh. I always thought that JS objects supported string and number keys separately, like lua. Nope!
Lua supports even functions and objects as keys:
Functions as keys is handy when implementing a quick pub/sub.
They do, but strings that are numbers will be reinterpreted as numbers.
[edit]
1 reply →