Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML Javascript splice()



  • High, i am trying to splice an array i have that i use to store data. The array is pulled from a custom fileIO that returns a JSON object with the array inside... That in itself isn't a problem however splicing just doesnt work in QT 5.9 or am i doing it wrong..

    function spliceTest() {
       var ar = ["t","t"]; 
       console.log(ar.length); // return 2 which is what it should be..
       ar.splice(1,1);
       // Array length should now be 1...
       console.log(ar) // returns "t", "t"  What happened??
       console.log(ar.length) // still returns 2...
    }
    

    Any help would be greatly appreciated :D

    Sinc., Alex


  • Lifetime Qt Champion

    Hi,

    Which exact version of Qt 5.9 are you using ?

    Can you provide a minimal compilable project that shows that behaviour ?



  • @SGaist Actually running the code on a different project gave me the correct results i guess it has something to do with my main project. I will attempt to see whats different between the two projects and why one is not running the splice command.



  • The solution was quite simple, ar, from my test project already had an alias property in that name, its a dumb mistake but the alias overides the var object and qt gets mixed up, changing the name of the temporary var fixed everything


Log in to reply