0

I have this data format.

[{"QualID":1,"Qualification":"Van Driver"},{"QualID":3,"Qualification":"Safety Cert"},{"QualID":4,"Qualification":"Welder"}] 

I need only qualification data with comma separator. How I get that? Thanks !

Van Driver, Safety Cert, Welder

I'm trying below way but its coming array value.

var jsonData = $.getJSON('/Qualification/GetAllQualificationTypesForDropdown', { user: $(USRNAME_CONTROL_ID).val() }, 'json');
            jsonData.done(function (data) {
                var nuarr = JSON.stringify(data);
                console.log(JSON.parse(nuarr).map(x => x.Qualification));

                            
                        }); 
5
  • 3
    JSON.parse(' ... ').map(x => x.Qualification)? Commented Mar 29, 2021 at 14:44
  • @evolutionxbox , its coming array value. I need string value with comma separator. Thanks ! Commented Mar 29, 2021 at 14:49
  • 2
    "coming array value" correct! If you'd like it to become a string, you could use .join(', ')? Commented Mar 29, 2021 at 14:49
  • Also, thank you for adding your attempt Commented Mar 29, 2021 at 14:50
  • perfect its working. Thanks @evolutionxbox Commented Mar 29, 2021 at 14:51

2 Answers 2

2

You should probably do something like this:

const values = [{"QualID":1,"Qualification":"Van Driver"},{"QualID":3,"Qualification":"Safety Cert"},{"QualID":4,"Qualification":"Welder"}] 

const result = values.map(({ Qualification }) => Qualification).join(", ")
console.log(result)

Sign up to request clarification or add additional context in comments.

Comments

0

I got answer by help of @evolutionxbox

var jsonData = $.getJSON('/Qualification/GetAllQualificationTypesForDropdown', { user: $(USRNAME_CONTROL_ID).val() }, 'json');
            jsonData.done(function (data) {

                var nuarr = JSON.stringify(data);
                var jsonstring = JSON.parse(nuarr).map(x => x.Qualification);
                console.log(jsonstring.join(', '));
                           
                        }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.