這裏是問題:JavaScript對象不是本地JavaScript metods像匹配()工作,更換等
我去這個代碼:
var str = {"Acc":10 , "adm_data":"Denied"};
當我做這樣的事情:
console.log(str.Acc.match(/[0-9]+/g)) // To Get the Integer Value from the "Acc" key
螢火蟲尖叫:
TypeError: str.Acc.match is not a function
console.log(str.Acc.match(/[0-9]+/g));
見圖片:
我總是做這樣的事情:
var str = "Hello _10";
console.log(str.match(/[0-9]+/g)) // This Works
爲什麼Object
一句話是不工作?
請幫忙!
PLEASE NOTE:
As Mentioned by
@Fabrício Matté.
The Issue was that I was trying to pass aninteger
Value to the.match
method which does not belong tointegers
. The solution was to do what@kundan Karn
Suggested. Something like:str.Acc.toString().match(/[0-9]+/g)// Coverting it first to string then match
. It Worked!
[SSCCE](http://sscce.org/)或沒有發生。不可能用你給出的例子重現。 http://jsfiddle.net/QgdUV/ –
試過你的代碼,它工作正常:) 我用nodeJS來測試它雖然 – Rami
@Fabricio無光澤...你能說出你的意思嗎?.. @投降的建議運作良好,但當我嘗試如下所示:'var str = {「Acc」:10,「adm_data」:「Denied」};'_注意**原始整數**值...這會給出相同的錯誤原因? –