• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

177
Views
Accessing array element from API data

so maybe you've heard of Splinterlands. This is from a bot that I'm trying to customize, but JS is so confusing to me. When I display the array with JSON.stringify(teamToPlay), I get this:

{ 
  "summoner": "167",
  "cards": [167, 162, 192, "", "", "", "", "fire", "", ""]
}

I'm trying to pull out "fire", the 8th element in the cards array. "cards" is an array, right? Appreciate your help.

almost 3 years ago · Santiago Gelvez
1 answers
Answer question

0

Let me explain you with another example

const info = {
    firstName: "priyam",
    lastName: "shah",
    birthYear: 1000,
};
console.log(info.firstName);
console.log(info["lastName"]);

This is how you can access objects. Now it's quite easy to find the 8th character from the array right ? arrName[index]

So it should be obj.cards[7] assuming you save this data coming from api to a variable called obj.

almost 3 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error