To access a JSON property, pass an argument as a reference

I'm currently developing a Facebook app using the JS SDK...

My objective is to implement a function that can make API calls to the Graph API:

This is what I have come up with so far:

function fetchUserData(data){
    FB.api('/me', function(response){            
         var info = response.data[0].name;
         alert(info);
    });
}

I attempted to run this code, but unfortunately, it did not yield any result.

fetchUserData("inspirational_people");

Answer №1

Are you passing the text string "inspirational_people" into your function and looking to retrieve a property of the response object with that exact name?

It's actually quite simple using basic JavaScript syntax: Any property accessible via object.propertyName can also be accessed using object["propertyName"].

In your situation, if you aim to retrieve

response.inspirational_people[0].name
, you would use response[reference][0].name – the specific value of reference is determined during runtime, ultimately giving you the desired result.

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

Is there a way to identify the visible portion of the browser window as seen by the user?

Looking at the image below, you'll notice that the website displays elements "A", "B", "C", "D", and "E". However, users may only see elements "A", "B", and a small portion of element "D" within their browser window. Some users may need to scroll down ...

The event emitted doesn't appear to be caught by EventBus.$on in Vue.js

Currently trying to trigger an event from router.beforeEach and listening for it in another component. Although the vue devtool confirms that the event is being triggered, my component seems unable to capture it. Thank you for your help. This is how I dec ...

Unable to retrieve the /socket.io/socket.io.js file in the client-side application

My server side application is currently hosted on heroku: The code snippet that is relevant to this issue is as follows: const express = require('express'), app = express(), server = require('http').createServer(app), ...

There seems to be a syntax error in the Textillate Plugin, where an IntegerLiteral was expected but ""

I am currently incorporating the Textillate plugin for text animation in my web application. However, I am encountering a Syntax error in Eclipse when defining the JavaScript for the animation, particularly with the 'in' definition. How can I res ...

Embedding a label's text directly as HTML code in an ASP.NET page

I attempted this CABC</td><td valign="top"><span class="progressBar pb3">document.getElementById('<%#Label8.ClientID%>').innerHTML</span></td></tr> I am trying to incorporate a jQuery script for a sales ...

What is the best way to upload and parse large files one line at a time with ExpressJS?

When dealing with uploading a large file to Express, I have successfully accessed the files object using the express-fileupload middleware. Here is an example of the files object: { myfile: { name: 'somelargefile.txt', data: <Buffer ...

What are the benefits of integrating firebase-admin-sdk with firebase-ui and firebase-client-sdk for both server-side and client-side authentication management?

I am currently working on implementing an authentication mechanism for my Next.js project. Specifically, I plan to utilize firebase-auth and firestore. My main goal is to keep important security logic on the server side to ensure safety. I want to avoid ex ...

Issue with the alphabetical ordering of subpages

My PageSidebar.js component lists child pages alphabetically. https://i.sstatic.net/DZro1.png However, when I navigate to a child page, the alphabetical order is not maintained. https://i.sstatic.net/fRVgO.png I've tried multiple solutions but hav ...

The response from the node is not accurate

In the index.js file, I have the following code snippet: function Answer(value) { this._val = value; } Answer.prototype.get = function get() { return this._value; } var lifeAnswer = new Answer(42); console.log(lifeAnswer.get()); var piAnswer = new ...

The URL for this page is not within the app's designated domains and will not open Facebook Dialogs (FB UI)

I am currently working on integrating Facebook UI Dialogs into my website. My goal is to add custom actions when users share a post from my site. I have created my app, added the app URL and domain (which is the same as the URL), and included all necessa ...

Efficiently managing AJAX requests in PHP

One aspect of my work involves a substantial amount of UI coding that requires sending AJAX requests to the backend PHP. I've been managing this by using: if(isset($_REQUEST["UniquePostName"])){ /* Do Something*/ } if(isset($_REQUEST["AnotherUniqueP ...

Mobile devices do not support internal link scrolling in Material UI

Currently, I'm utilizing internal links like /lessons/lesson-slug#heading-slug for smooth scrolling within a page. While everything functions perfectly on desktop, it ceases to work on mobile view due to an overlaid drawer nav component. Take a look a ...

Utilizing jQuery to generate dynamic nested divs within the ul li tags

I am looking to dynamically generate nested divs within a ul li. The goal is to create the following structure programmatically: <ul> <li> <div class="videoThumbnail"> <img src="./img6.jpg" /> &l ...

Transforming a LinkedHashMap<String, MyClass> into a Java object

Is there a way to convert this JSON string structure into a Java object: { "summary": { "totalMR":4.599000000000903E12, "totalMA":1.9174920000386694E11, "totalQA":5.1111111181E9, "totalQR":1.000020666115264E11 }, "result": [{},{}], " ...

What is the method to access nested JSON data returned from the Angular JS $http service?

Here is the main JSON file I am using { "chartType" : ["column", "column", "pie"], "chartTitle": ["Number of teams", "Number of consumable items","Number of employees in charge"], "yAxisTitle": ["Teams", "Consumables", "Employees"], "seriesName": ...

implementing MongoDB Query using relational database driver technique

When working with RDMS, to execute "Select emp_name from Employee where empid=100", I would typically write the following code: String query = "Select emp_name from Employee where empid=100" Statement stmt = DriverManager.getConnection(db, user, passw ...

Including the file path to an image in a CSS module within a React component from the public directory

I'm currently facing a challenge with adding an image as a background, especially since the image is located in a public folder structure like this: -public -images -image.png -src -assets -components -index.tsx -index.module.css (I want to use the ...

Interactive questioning system using Javascript/jQuery for Quick Responses

Hi there! I'm new to StackOverflow and a bit of a beginner when it comes to javascript/jquery. My current project involves creating a chat interface that looks like SMS text messages. Right now, I have users inputting text and using javascript to disp ...

MUI Gradient Tracked Button

Take a look at this Codepen example I created. It showcases a hover effect where the gradient follows the mouse cursor. In order to achieve this effect, I have defined two CSS variables - --x and --y, to keep track of the mouse position on the button. The ...

"Enhancing User Experience with Bootstrap's masonry layout feature while retaining scroll position

I'm faced with a puzzling situation and I can't seem to find the solution. Currently, I am utilizing Bootstrap 5 along with the masonry layout as recommended here: https://getbootstrap.com/docs/5.0/examples/masonry/, and it is working perfectly. ...