ist there a better way to itereste the keys of i j...
# javascript
t
ist there a better way to itereste the keys of i js object today compared to the
keys()
method described here? https://discuss.kotlinlang.org/t/js-interop-for-in-and-for-of-loop-of-dynamic-objects/7507/4
b
Don't think so
t
i wish i could just do
for (i in object)
like i'd do in javascript 😕
b
You could make the solution provided more flexible, though:
Copy code
inline fun asMap(jsObject: dynamic) = js("Object")
    .entries(jsObject)
    .unsafeCast<Array<Array<dynamic>>>()
    .map {
        it[0].unsafeCast<String>() to it[1]
    }.toMap()
    
fun main() {
    val x:dynamic = js("{name:'ok', otherName: 'notOk'}")
    
    println(asMap(x).keys)    
    println(asMap(x).values)
    for((k, v) in asMap(x)) {
        println("Key: $k, Value: $v")
    }
}
t
yeah thats true, for sure, yet doesn't improve the code significantly in that case. but thank you 🙂
b
These might be useful to you
t
thanks! i'll have a look 🙂