@Wieland said:

Qt.createQmlObject('import QtQuick 2.6; Rectangle {color: "red"; width: 100; height: 100; function nix(){ var arr=["function","two"]; console.log(arr)} Component.onCompleted:nix() }', mainWindow, "dynamicSnippet1");

Good to hear, must be solved then. Thanks!