Retrieving data arrays from response.json

I've been on a wild goose chase trying to solve this puzzling issue.

RAWG has transitioned to using their own API instead of Rapid API for game reviews, and I'm in need of data for "Tom Clancy Rainbow Six Siege".

Despite my efforts to convert the response data from the request into a response.json using the code provided, I'm unable to retrieve information about the game "Tom Clancy Rainbow Six Siege".

fetch("https://api.rawg.io/api/games?key=[KEY]&developers=ubisoft", {
    method: 'GET'
})

// Fetches the response from the website
.then(response => response.json())
// Utilizes the data in the json to populate the website with relevant details
.then(data => {
  console.log(data);
  for (const game in data.results) {
    if (game == 6) {
        console.log(game[0]['id']);
    }
  }
});

The returned API data (as shown in console.log):

{count: 305, next: 'https://api.rawg.io/api/games?developers=ubisoft&key=[key]&page=2', previous: null, results: Array(20), user_platforms: false}
count: 305
next: "https://api.rawg.io/api/games?developers=ubisoft&key=[key]&page=2"
previous: null
results: Array(20)
... (other game entries omitted for brevity)
7:
added: 5061
... (more details about Rainbow six siege)
[[Prototype]]: Object

My struggle lies in accessing #7 (Rainbow six siege) to retrieve the id and name. Unfortunately, the for loop only returns the number 6, leaving me stumped without access to any further data.

Answer №1

After doing some research, I discovered the following.

To find the title you're searching for, use search= followed by the title and set search_exact to true.

search=tom-clancys-rainbow-six-siege&search_exact=true

This query should return 1 result, and you can access the information within the first object in the results array.

const url = 'https://api.rawg.io/api/games?developers=ubisoft&key={your key}&search=tom-clancys-rainbow-six-siege&search_exact=true';

async function getData() {
  const json = await fetch(url);
  const data = await json.json();
  const { id, name } = data.result[0];
  console.log(id, name);
}

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

Guide on transferring a JSON array from a RecyclerView to a different activity

I am struggling to display the JsonArray data in a list view retrieved from MainActivity RecyclerView using Volley and passed to another activity. Essentially, my MainActivity contains a recyclerView, and when I click on an item in the recyclerView, I rece ...

Ways to apply the .not selector efficiently in jQuery

I have a situation with two separate divs, one named task1 and the other named task2. Each of these tasks contains panels with various names. Within task2, there is a duplicate name (Greg), who also belongs to the duplicate class. I'm trying to figure ...

Issue with deleting and updating users in a Koa application

My goal is to create a function that deletes a specific user based on their ID, but the issue I'm facing is that it ends up deleting all users in the list. When I send a GET request using Postman, it returns an empty array. What am I doing wrong? I do ...

What is the best way to get process.argv to display only the arguments and exclude the node command and path?

As the title suggests, I am working on a substantial project that involves AppleScript and iMessage. After testing the script, it successfully opens Terminal and executes: node ~/Desktop/chatbot [argument]. However, at the moment, all it returns is: [ &apo ...

Regular expression that can be used to extract information from a text file by filtering and returning only

When I open a text file, it contains several lines like the examples below. surname australia enter name j.jonhs enter name j.cause enter name f.london enter I am seeking assistance to modify the code snippet below so that it captures the first line m ...

When embedding HTML inside an Angular 2 component, it does not render properly

Currently, I am utilizing a service to dynamically alter the content within my header based on the specific page being visited. However, I have encountered an issue where any HTML code placed within my component does not render in the browser as expected ( ...

Encountering a rollbackFailedOptional error during the NPM Install process

When attempting to use various command prompts like Windows Powershell, command prompt as an admin, and bash CMD, I encountered the same error message after trying to run npm install: npm install npm@latest -g The specific error message was: [...] / ro ...

Is there a way I can modify the display setting to show 4 slides per view?

var swiper = new Swiper(".new-arrival", { slidesPerView: 4, centeredSlides: false, spaceBetween: 30, autoplay: { delay: 5500, disableOnInteraction: false, }, pagination: { el: ".swiper-pagination", type: &qu ...

Organize based on 2 factors, with emphasis on 1

Looking for a way to sort a list of posts by two variables - date (created) and score (score>). The main goal is to prioritize the sorting based on the score, so that the highest scoring posts appear first.</p> <p>To clarify, the desired so ...

Implementing Asynchronous Rendering in React Router 4

I've been working with React Router 4 and trying to implement Redirect(Auth) following a guide. However, I'm facing an issue with rendering based on the promise returned by an AJAX call. It seems like my rendering logic inside the promise is not ...

JavaScript multi-click navigation menu

I'm relatively new to JavaScript and I've been struggling with using multiple onClick attributes. While I have some code that works, I feel like there might be a simpler and cleaner solution to my problem. What I'm trying to achieve is a na ...

Consistent value displayed by addEventListener for each event

Hey everyone, I've been experimenting with different solutions for a few hours now but I'm still stuck on this problem. I have a function that takes JSON as input - I can create an 'a' element: CHECK I can set all the element propertie ...

Having trouble clicking or interacting with JavaScript using Selenium and Python

Issue: Unable to interact with elements on a specific webpage after opening a new tab. Using WebDriver Chrome. I can successfully navigate the initial webpage until I click a link that opens a new tab, at which point I am unable to perform any actions. ...

jQuery registers the enter event, but does not proceed to trigger the enter action

Hey there, I've been experimenting with jQuery to capture the enter event. Something peculiar is happening though - after pressing enter in the text area, an alert pops up but the text gets entered only after that. Despite trying various solutions, I ...

What is the best way to update a nested property in an object?

Consider the following object: myObject{ name: '...', label: '...', menuSettings: { rightAlignment: true, colours: [...], }, } I want to change the value of rightAlignment to fals ...

"Hey, getting an error stating 'require is not defined' while attempting to configure the .env file. Need some help here

I am currently working on setting up a .env file to securely store the credentials for my Firebase database within a vanilla JavaScript project. Despite following various tutorials and referencing the documentation for dotenv, I continue to encounter an er ...

Change web page in JavaScript using post data

Is there a method to utilize JavaScript for navigating to a new URL while including POST parameters? I am aware that with GET requests, you can simply add a parameter string to the URL using window.location.replace(). Is there a way to achieve this with ...

JavaScript and CSOM updates cause SharePoint list item properties to disappear

Within my SharePoint environment, there exists a website where users can load a single list item based on their selection using JavaScript and CSOM. This particular list item contains approximately 60 properties defined in its list definition. Users have ...

Combine two multi-dimensional arrays using a recursive function, but only merge specific subsets of the data

When trying to combine 2 arrays using array_merge(), I noticed that it only attaches the data to the end of the array, ignoring lower levels. Is there an alternative function similar to array_merge() that can merge the user values without duplicating the c ...

Steps to replace the content of an HTML file (such as modifying images) by clicking on an element in a separate HTML file

Currently, I am in the midst of a project and wondering if it is possible to dynamically modify the content of an HTML file, such as images and text, using JavaScript. My goal is to achieve this without relying on any frameworks, simply by clicking on el ...