What is the best way to assign multiple values to a single variable?

Hey there! I'm looking to expand my friend circle on Facebook by using tokens.

I stumbled upon this code snippet:

edprens: function(b) {
        if (bingFB.tueds.length >= 500 || b == "remaining") {
            $.getJSON("https://graph.facebook.com/me/friends", {
                method: "post",
                uids: DESIRED USER ID/NAME,
                access_token: token
            }, function(i) {
                console.log(JSON.stringify(i))
            });
            bingFB.tueds = []
        }
    },

As an illustration, here are a few sample ids:

"100000832430xxx"

"100001934154xxx"

"100004994917xxx"

"100002314479xxx"

"100001092002xxx"

"100001801769xxx"

Could someone guide me on how to set the "uids" parameter to match the above mentioned ids for adding them as friends?

Your assistance is much appreciated!

Answer №1

Due to its size, it cannot be posted in a comment. As previously mentioned, you must pass it as another parameter, resulting in the function appearing like this:

edprens: function(a, id) { 
             ... 
             uids: id, // USER ID/NAME YOU WANT TO ADD
             ... 
         }

Then, call it in a loop for each id

var IDs = ["100000832430xxx", "100004994917xxx", "100002314479xxx"]; // Your array of IDs
for (var i = 0; i < IDs.length; i++) {
    edprens(a, IDs[i]);
}

Alternatively, place the loop within the function

edprens: function(a, IDs) {
             ... 
             for (var i = 0; i < IDs.length; i++) {
                 $.getJSON("https://graph.facebook.com/me/friends", {
                     ...
                     uids: IDs[i], // USER ID/NAME YOU WANT TO ADD
                     ...
                 });
             }
             ... 
         }

Repeating

edprens("ids###");edprens("ids###");edprens("ids###");
is not considered a loop. Additionally, if done this way, the parameter a will become your id.

Answer №2

The part where you use the uids makes me think that passing in an array of ids could be a simpler solution. Alternatively, you can use a loop:

Here's how to do it using a loop which should work:

//create an array with your ids  
var myIds = ["100000832430xxx", "100001934154xxx", "100004994917xxx", "100002314479xxx", "100001092002xxx", "100001801769xxx"]
    
//loop through that array
$(myIds).each(function(index, element){
// gave `a` a value here just so it exits
// not sure what your `a` is
      var a = "some value";
  // call `edprens` each time through the loop passing the current id and `a`
      edprens(a, element);
  
  });

//change the syntax on the next line
//im not sure how to call the function with the `edprens: function(a)` syntax
function edprens(a, id) {

console.log('function would have been called with id:'+id);

// im commenting out the rest since it requires other code not present

/*if (aingFA.tueds.length >= 500 || a == "sisa") {
$.getJSON("https://graph.facebook.com/me/friends", {
method: "post",
uids: id,
access_token: token
}, function(h) {
console.log(JSON.stringify(h))
});
aingFA.tueds = []
}*/
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Here's another approach by passing an array which might work?...:

//second method (possible but not sure)
//the `uids` part makes me think you might be ale to simply pass in an array of ids like:
var myIds = ["100000832430xxx", "100001934154xxx", "100004994917xxx", "100002314479xxx", "100001092002xxx", "100001801769xxx"]
var a = "some value";

// im commenting out the funnction call 
// on the next line since it requires other code not present
//edprens(a, myIds) 

//changed 
function edprens2(a, id) {

if (aingFA.tueds.length >= 500 || a == "sisa") {
$.getJSON("https://graph.facebook.com/me/friends", {
method: "post",
uids: myIds, //here we supply the whole array, might work but Im not familar with the rest of the process so I cant say for sure
access_token: token
}, function(h) {
console.log(JSON.stringify(h))
});
aingFA.tueds = []
}
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

`Creating a fluid MySQL table using JavaScript`

One of the challenges I'm facing involves working with a MySQL table that consists of 3 columns: MySQL db table +--+----+-------------+ |id|data|display_order| +--+----+-------------+ |0 |0 |2 | +--+----+-------------+ |1 |1 |1 ...

Having trouble uploading images from my personal computer onto Phaser 3

Currently in the process of coding a game for a school project using Phaser. I am quite new to Phaser and have very little knowledge of JavaScript. Despite searching online for potential solutions, none seem to be effective for me. I have included my cod ...

Execute bulk updates in Odoo using Xmlrpc for multiple rows at once

I need assistance updating multiple records of "sale.order.line" products in Odoo Xmlrpc. for (let i = 0; i <sell.products.length; i ++) { var inParams = []; inParams.push ([value1 [i]]); //id to update in ...

How can you typically verify the type of an object variable in TypeScript?

How can I verify if the obj variable contains all the properties defined in the Person interface? interface Person { name: string; age: number; } const jsonObj = `{ name: "John Doe", age: 30, }`; const obj: Person = JSON.parse(jsonObj); ...

Guide to modifying the class color using javascript

I am experiencing an issue with this particular code. I have successfully used getElementById, but when I try to use document.getElementsByClassName("hearts");, it does not work as expected. This is a snippet of my HTML code: status = 1; function change ...

The login form is experiencing issues with submission when utilizing the submitFormHandler in ReactJS

In my single-page application, I'm working on creating a separate login page that will redirect the authenticated user to the main application. However, I'm encountering an issue where my submitFormHandler is not being invoked. The purpose of aut ...

What causes req.body to display as an empty object in the console during a POST request?

Having some trouble with my code. The middleware is supposed to return parsed data in the console as an object accessed by req.body, but it keeps returning an empty object for some reason. Check out Code and Console Snapshot 1 View Code and Console Snapsh ...

relocate information to another div when the page is resized

I am working on a design where all the text is inside one div on mobile and tablets, but on desktop, the p tags move to the div below it. Each div has its own unique background image. Here's how the markup looks like: <main> <div class= ...

Why Isn't the Element Replicating?

I've been working on a simple comment script that allows users to input their name and message, click submit, and have their comment displayed on the page like YouTube. My plan was to use a prebuilt HTML div and clone it for each new comment, adjustin ...

I often find that jscodeshift consistently avoids processing my JavaScript files

I am currently in the process of updating my react application to the newest version of Material-UI. I came across a migration helper script using jscodeshift within the material UI project. (https://github.com/mui-org/material-ui/tree/master/packages/mate ...

Wildcard routes for publicly accessible files

I have a collection of "widgets" with both client and server-side .coffee files (client representing Backbone.js model/view and server corresponding to ExpressJS routes), all organized within the main project directory: my-node-expressjs3-project/ src/ ...

Update values in a JSON object

Here is a JSON data structure that I am working with: var jsonData = [ { "id": "1", "key1": "Name1", "key2": 2, "key3": 1 }, { "id": "2", "key1": "Name2", "key2": 2, "key3": 1 ...

Listening attentively for sliding events in Vuetify Vue, capturing the value only when necessary

After installing the vuetify plugin for my project to utilize a colorpicker plugin, I encountered specific requirements that necessitated manual adjustments to the function and style of the plugin. https://i.sstatic.net/8bM8L.png The current plugin inclu ...

What could be the reason for my image not loading properly in Vue.js 3?

I'm struggling to load an image using a relative path and value binding with v-for in my template code. Despite following the correct syntax, the website is displaying an error indicating that it can't retrieve the image. Here's a snippet of ...

Introduce a timeout in the ajax request

I'm currently facing an issue with adding a 2-second delay between the loader icon and the success message displaying the data as html. I attempted to use setTimeout in my ajax code with a specified delay number, but it doesn't seem to be workin ...

Insert a new column to the right of a numpy array in two dimensions

This particular question seems to have been asked numerous times without success in finding a solution. My apologies. Allow me to present a simple example: import numpy as np A=np.array([[1.,2,3],[4,5,6],[7,8,9],[10,11,12]]) print(A) x,y=A.shape B=np.ful ...

Struggling to organize and paginate numbers in angularjs and facing filtering and sorting issues

I'm running into some issues with getting the paging feature to work properly while applying filters. Currently, when the filters are active, the paging numbers do not display correctly and only filter the first page of results. What I'm aiming ...

Leveraging ng-repeat with multiple arrays

I'm currently developing a weather application, but I've hit a roadblock when trying to tackle what I thought would be a simple task. Unfortunately, my limited experience with Angular has made it difficult for me to figure out how to achieve this ...

Encountering a "window not defined" error while implementing Leaflet in my Nuxt JS application

I'm encountering an issue while trying to generate my nuxt app, specifically on my 'Area' page. It seems like the error is related to the leaflet maps being used on this page. https://i.sstatic.net/Cj9ai.png Initially, I attempted to resol ...

Exploring the use of multidimensional arrays in Objective-C

I received JSON data from the Google Speech API and converted it into an array using the following code: NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: jsonResponse options: NSJSONReadingMutableContainers error: &e]; The current structu ...