jquery - How to Fetch an array of strings in javascript? - Stack Overflow

I get a list of tag names from the server and fill getedTags with data.my problem is data that it is a

I get a list of tag names from the server and fill getedTags with data. my problem is data that it is a type of string while it must be an array , data value: "["HTML","CSS"]" but i need ["HTML","CSS"] how can i fetch an array of strings and add to getedTags variable?

var getedTags = [];
$.get(getTagurl,
    function (data) {

        getedTags = data;

    });

I get a list of tag names from the server and fill getedTags with data. my problem is data that it is a type of string while it must be an array , data value: "["HTML","CSS"]" but i need ["HTML","CSS"] how can i fetch an array of strings and add to getedTags variable?

var getedTags = [];
$.get(getTagurl,
    function (data) {

        getedTags = data;

    });
Share Improve this question asked Aug 6, 2017 at 8:51 Soheil AlizadehSoheil Alizadeh 3,06611 gold badges32 silver badges57 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

You can use JSON.parse() from parse string to object.

var getedTags = [];
$.get(getTagurl,
function (data) {
    getedTags = JSON.parse(data);
});

You should convert the data you get from server into array. I presume the data type you are getting is JSON.

You can do JSON.parse(data) to convert in Object.

You need to use JSON.parse()

https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

It will make a javascript object or array out of string.

var getedTags = JSON.parse(data)

To reverse this, you can use JSON.stringify() https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

It will turn your array or javascript object into a string.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745100549a4611246.html

相关推荐

  • jquery - How to Fetch an array of strings in javascript? - Stack Overflow

    I get a list of tag names from the server and fill getedTags with data.my problem is data that it is a

    10小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信