javascript array as a list of strings (preserving quotes)

前端 未结 5 799
刺人心
刺人心 2021-01-31 16:05

I\'ve got an array of strings. When I use .toString() to output it the quotes are not preserved. This makes it hard to build the mysql query using an \"in\". Consider the fol

5条回答
  •  死守一世寂寞
    2021-01-31 16:50

    Store the quotes:

    var names = ["'item1'","'item1'","'item3'"];
    alert('IN (' + names[1] + ')'); // IN ('item1')
    

提交回复
热议问题