[Javascript] jQuery.each()遍歷陣列元素@ 碎碎念 | jquery each dom element
jquery的eachfunction通常是用來遍歷選擇的元素們例:$(a).each(function(index,value){ console.log(this.href); });但現在是要使用在array陣列上面,忽然不知道要怎麼使用,紀錄一下。這樣使用:$.each(target_array,function(index,value){});constnumbers=[1,2,3,4,5]; $.each(numbers,function(index,value){ console.log(`${index}:${value}`); });--轉自 https://www.sitepoint.com/jquery-each-function-examples/[1]以下為原文Thisisanextensiveoverviewofthe jQuery.each() function—oneofjQuery’smost...
jquery的each function通常是用來遍歷選擇的元素們
例:
$(a).each(function(index, value){ console.log(this.href); });但現在是要使用在array陣列上面,忽然不知道要怎麼使用,紀錄一下。
這樣使用:
$.each( target_array, function(index, value){});
const numbers = [1, 2, 3, 4, 5]; $.each(numbers, function(index, value){ console.log(`${index}: ${value}`); });--
轉自 https://www.sitepoint.com/jquery-each-function-examples/[1]
以下為原文
This is an extensive overview of the jQuery.each() function — one of jQuery’s most important and most used functions. In this article, we’ll find out why and take a look at how you can use it.
This popular article was updated in 2020 to reflect current best practices and to update the conclusion’s advice on native solutions using modern JavaScript. For more in-depth JavaScript knowledge, read our book, JavaScript: Novice to Ninja, 2nd Edition[2].
What is jQuery.each()
jQuery’s each() function[3] is u...