Javascript PHP var數組將雙引號放入 (Javascript PHP var array puts double quotes in)


問題描述

Javascript PHP var數組將雙引號放入 (Javascript PHP var array puts double quotes in)

I can't work this one out...

I have a var called data which consists of exactly this.. 

"12-9-2011","13-9-2011","14-9-2011","15-9-2011","16-9-2011"

including the quotes

but when i come to use the javascript command unavailableDates = [data];

it adds more quotes on either end... how can i stop this..

it makes unavailableDates equal ""12-9-2011","13-9-2011"...15-9-2011","16-9-2011","

you see with quotes on the ends...

Any way i can stop this ?

Thanks

Lee


參考解法

方法 1:

If you use a string in a literal array it will just be an array with a single string, it won't evaluate the string.

Split the string into an array instead:

unavailableDates = data.substr(1, data.length - 2).split('","');

(by LeeGuffa)

參考文件

  1. Javascript PHP var array puts double quotes in (CC BY-SA 3.0/4.0)

#Variables #javascript






相關問題

使用 htaccess 從基本 URL 中刪除變量 (Remove variable from base URL with htaccess)

如何將解碼的數據包數據和標頭輸出組合到單個變量/字典中以進行字符串搜索 (How to combine decoded packet data and header output into a single variable/dictionary for string searches)

@Ruby on Rails 中的變量 (@ variables in Ruby on Rails)

xslt 將變量發送到另一個模板 (xslt send variable to another template)

變量被評估為任何東西 (Variable Being Evaluated as Anything)

獲取python函數的變量 (Get a variable of python function)

讀取 url JQuery 中的 GET 變量 (read the GET variables in url JQuery)

使用變量名作為數組索引 (Using variable name as array index)

Javascript PHP var數組將雙引號放入 (Javascript PHP var array puts double quotes in)

兩個不同定義之間的變量 (Variable between two different definitions)

Tkinter 組合框 Python (Tkinter Combobox Python)

有沒有辦法在 Python 中使用變量中的字符串調用方法? (Is there a way to call a method in Python using a string inside a variable?)







留言討論