foreach object/array in jQuery

后端 未结 5 2000
滥情空心
滥情空心 2021-02-08 15:02

I have a problem, i have X in my code, now I want to foreach this object/array its out put. - look my code.

$(\"#d         


        
5条回答
  •  心在旅途
    2021-02-08 15:28

    I'm not exactly sure what you're looking for, but I'm guessing that the jQuery.each() method will help. You can use it to iterate over arrays, objects, and more.

    var arr = [ "one", "two", "three", "four", "five" ];
    
    jQuery.each(arr, function() {
         $("#" + this).text("My id is " + this + ".");
         return (this != "four"); // will stop running to skip "five"
    });
    

提交回复
热议问题