Home > front end >  From Array to individual string in Jquery?
From Array to individual string in Jquery?

Time:01-27

there is a problem with my code I try to split array values to single individual strings that contains part of links.

I tried with dele.join() , but still the output is single string with coma separation

$(function () {

            $("#selectedel").click(function () {
                var dele =[]; // Array look like this  ["/delete.php?id=1","/delete.php?id=2","/delete.php?id=3"]
                $.each($("input:checkbox[name='dele']:checked"), function () {
                    dele.push($(this).val());

                });
                console.log(dele.toString());
                console.log(dele.join(","));
            })


        });

output of this code is

/delete.php?id=1,/delete.php?id=2,/delete.php?id=3

The output that i want is

/delete.php?id=1
/delete.php?id=2
/delete.php?id=3

Which in the end i want to open this links with window.open() at once .

Thank you in advance

CodePudding user response:

Try this one

["/delete.php?id=1", "/delete.php?id=2", "/delete.php?id=3"].map((url) => {
  const xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function() {};
  xhr.open('GET', url);
  xhr.send();
});
  •  Tags:  
  • Related