Javascript/Jquery Convert string to array

后端 未结 4 1537
北恋
北恋 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 04:03

    Assuming, as seems to be the case, ${triningIdArray} is a server-side placeholder that is replaced with JS array-literal syntax, just lose the quotes. So:

    var traingIds = ${triningIdArray};
    

    not

    var traingIds = "${triningIdArray}";
    

提交回复
热议问题