Hello, I want to know, which data structure should...
# multiplatform
j
Hello, I want to know, which data structure should I use in JS target so it will get compiled into a native JS array without extra overhead? Mainly, I need access to `push`/`pop` and other js-exclusive array methods
j
kotlin.Array
is mapped to JavaScript
Array
.
j
I usually just write an external interface for a MutableJsArray and then init with
js("[]")
j
@jw Thanks you very much! I never knew you can directly run js code, I will go with interface approach too then
g
Why using an external interface instead of just kotlin.Array?
j
Because I can't push/pop with it
g
Sorry, I wasn't clear, I was thinking about an extension function on Array that was calling js("this.pop()") for example, but not sure it works.
j
Hmm, I will try
Nah, this does not work
Copy code
fun <T> Array<T>.push(item: T) {
    js("this.push(item)")
}
gets compiled into
Copy code
function push(_this__u8e3s4, item) {
    this.push(item);
  }
j
Do
val array = this
and then
array.push
inside the JS string