Combine all Values from List Model into one string

101 Views Asked by At

I have the following:

ListModel {
  id: myModel
  ListElement {
    name: "Number1"
  {
  ListElement {
    name: "Number2"
  {
  ListElement {
    name: "Number3"
  {
}

I want to define a variable that combines all of the "name" fields into a comma delimited string, but I have to do it within a for loop as I frequently append new elements to "myModel". Something like this:

property var stringOutput = ""
for (var i = 0; i < ListModel.length; ++i) {
  stringOutput = stringOutput + "," + ListModel[i].name
}

Resulting in:

stringOutput = "Number1,Number2,Number3"
0

There are 0 best solutions below