1

I have json file 'stars.json':

   {"person":
 [
      {
        "name": "a"
      },
      {
        "name": "b"
      },
      {
        "name": "c"
      },
      {
        "name": "d"
      }
    ]
}

then I would like to send data to kendo element:

 $('#grid').kendoDropDownList({
     autoWidth: false,
        filter: "startswith",
        value: self.valore,
        optionLabel: "Select value...",
        dataSource: {

        }
 });

What should I do in the datasource to convert json to simple array? I would like to get something like this:

data=['a','b','c','d'];
1

2 Answers 2

2

You can use simply array function to get the results what you required

Suppose

var data = {"person":
 [
      {
        "name": "a"
      },
      {
        "name": "b"
      },
      {
        "name": "c"
      },
      {
        "name": "d"
      }
    ]
}

then use the array map function like this

var newData = data.person.map(function(obj){
    return obj.name
});
console.log(newData)
Sign up to request clarification or add additional context in comments.

Comments

2

Considering there's a variable person with value:

{"person":[{"name":"a"},{"name":"b"},{"name":"c"},{"name":"d"}]}

you can simply do:

person.person.map((o)=> o.name)

Comments

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.