2015-02-23 106 views
0

我有一個AJAX表達式獲取從一個URL和成功功能信息是應該輸出第一數組中的元素,所以我迅速作出執行此函數得到的元件:混淆從陣列

success: function(data) { 
      console.log(data[1]); 
      $('<div id="allResults">'+ alert(data[1].get[0]) +'</div>').appendTo('#results').html(); 

     } 

但由於某種原因.get[0]是未定義的屬性。我得到的錯誤:Uncaught TypeError: Cannot read property '0' of undefined ..

console.log輸出這樣的:

["The Killers", "The Beatles", "The Kinks", "The Orb", "The Wire", "The Simpsons", "Thoroughbred", "The Raven", "Thylacine", "Thor"]

我不知道我怎麼能得到第一個元素...任何想法?

+2

您是否嘗試過使用數據[0] [0]'。它看起來像我的雙維數組 – 2015-02-23 21:20:56

+3

.get []是什麼?你試圖達到的目的可以通過數據完成[1] [1]。 – roshan 2015-02-23 21:22:14

+0

你正在通過由'[「殺手」,「披頭士樂隊」,「扭結」,「The Orb」,「The Wire」,「辛普森一家」組成的'data [1]'' ,「Thoroughbred」,「Raven」,「Thylacine」,「Thor」]'當你試圖從數據的第一個元素獲取數據時,你可以告訴我們什麼是輸出log'data [0]' – hiren 2015-02-23 21:24:03

回答

1

JavaScript中的數組還沒有得到原生方法get,因此你會得到錯誤。要實現二維使用data[0][1]