There is a loop in the js click event. Can I click to execute the loop?

let arr = [

]
                {id:1,text:""},
                {id:2,text:""},
                {id:3,text:""}
                ];

let items = [];
$("- sharpadd") .click (function () {
for (var i = 0polii

    items.push(arr[i]); 
 }  

})
/ / if written in this way, all the data of arr will be added directly. Hopefully, one click to add an id in arr

Jun.07,2021

you can first determine the id, and then make a comparison
var id =''

$("-sharpadd").click(function(){
    for(var i = 0;i<arr.length;iPP){
        if (id === arr[i].id) {
            items.push(arr[i]); 
        }
    }  
})

closure + immediately execute function implementation:

$('-sharpadd').click(
    (function() {
        let count = 0;
        return function() {
            items.push(arr[countPP]);
        };
    })()
);

  // indexid
  let index = 0;
  let arr = [
    {id:1,text:""},
    {id:2,text:""},
    {id:3,text:""}
  ];
  let arrLength = arr.length;
  let items = [];
  document.getElementById("add").onclick = function(){
    // 
    if (index <= arrLength - 1) {
      items.push(arr[index]);
      // 
      indexPP;
    }
    console.log(items);
  }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf88bb-54d63.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf88bb-54d63.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?