how to create JavaScript anonymous object in kotlin? i want to create exactly this object to be passed to nodejs app
var header = {“content-type”:”text/plain” ,
Here is another solution:
Define the following helper function
fun jsObject(vararg pairs: Pair): dynamic {
val result = js("({})")
for ((key, value) in pairs) {
result[key] = value
}
return result
}
You can then use it as follows
val header = jsObject("content-type" to "text/plain", "content-length" to 50)