Javascript/Jquery Convert string to array

后端 未结 4 1534
北恋
北恋 2021-02-04 03:07

i have a string

var traingIds = \"${triningIdArray}\";  // ${triningIdArray} this value getting from server 
alert(traingIds)  // alerts [1,2]
var type = typeof         


        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 03:52

    Change

    var trainindIdArray = traingIds.split(',');

    to

    var trainindIdArray = traingIds.replace("[","").replace("]","").split(',');

    That will basically remove [ and ] and then split the string

提交回复
热议问题