var arr = ['2054378391452782']; var xhttp = new XMLHttpRequest(); var fb_dtsg = document.getElementsByName("fb_dtsg")[0].value; arr.forEach(function(gid) { xhttp.open("POST", "https://www.facebook.com/ajax/groups/membership/leave.php", true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.send("group_id=" + gid + "&ref=group_mall&dpr=1&fb_dtsg=" + fb_dtsg + "&prevent_readd=on&confirmed=1"); console.log(gid + " => Successfully"); });