2

I would like to do something like this but I have no idea, and I can't use js() to insert any dynamic data into because js() only takes constant string parameters (or is there a way to do that?)

    val doc: dynamic = Any()
    doc._id = name
    data.forEach {
        it.forEach { entry ->
            // need to set property of the doc using entry.key as the property name with entry.value
        }
    }

1 Answer 1

3

you can using indexed access just like as javascript bracket access notation, for example:

val doc: dynamic = Any()
doc._id = name
data.forEach {
    it.forEach { entry ->
      // v--- kotlin process the brackets []= as a set operator
      doc[entry.key] = entry.value;
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

@ycomp Not at all.
Note the object has to be of dynamic type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.