我正在使用 id 從 DOM 中提取一個輸入元素數(shù)組,并使用 .map() 循環(huán)遍歷數(shù)組。我的代碼有效,但是 currentValue 和 index 被切換了:ports = $("#edit_display_control_ports > li > input").map(function(currentValue, index){ return index.value;}).toArray(); 同樣,此代碼有效。根據(jù)文檔,map() 函數(shù)的第一個參數(shù)應(yīng)該是 currentValue,第二個參數(shù)應(yīng)該是 index。但是我必須切換兩者。currentValue 返回數(shù)組的索引,而 index 參數(shù)返回元素。
array.map() - currentValue 和 index 參數(shù)是否切換?
Qyouu
2021-12-02 16:38:11