[問題] prototype.push.apply 新增到陣列問題

看板Ajax作者 (客倌來看看!)時間10年前 (2014/12/21 20:14), 10年前編輯推噓2(202)
留言4則, 3人參與, 最新討論串1/1
var arr = new Array ("001","002","003"); var file = document.getElementById('file').files[0]; if (file) { i = String(file.name); arr.prototype.push.apply([i]); } 利用file button選取檔案抓取檔名 並且把檔名強制轉為字串 然後使用push新增到陣列 請問這樣寫對嗎? for(j=0;j<=arr.length;j++) { i = String(file.name); arr.prototype.push.apply(???); } document.write(arr); } 如果要使用for迴圈的話是要這樣寫嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.231.6.103 ※ 文章網址: http://www.ptt.cc/bbs/Ajax/M.1419164069.A.890.html ※ 編輯: kolocoyima (61.231.6.103), 12/21/2014 20:16:49

12/21 23:43, , 1F
不是只要arr.push就好
12/21 23:43, 1F

12/22 02:28, , 2F
var arr=[]; ...arr.push(file[0].name);
12/22 02:28, 2F

12/22 02:28, , 3F
s
12/22 02:28, 3F

12/22 08:32, , 4F
沒事不要亂用建構式 會很慘
12/22 08:32, 4F
文章代碼(AID): #1KbhcbYG (Ajax)
文章代碼(AID): #1KbhcbYG (Ajax)