Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

79
Views
Retrieve and display individual object from array Javascipt/React

Suppose I have an array:

{
    "data": [
        {
            "id": 9,
            "body": "This is the first body of text,
            "availability": "internal",
            "title": "Test",
            "posted_by": "Test"
        },
        {
            "id": 10,
            "body": "This is the second body of text",
            "availability": "internal",
            "title": "TEST2",
            "posted_by": "TEST2"
        },
}

My aim is to be able to print a specific "title" or "body" in my React app. Previously I had the data in JSON where I could simply use something like data.title[0] which would be Test.

Now I pull data using the following code:

componentDidMount() {
    axios
      .get(
        "API_KEY"
      )
      .then((res) => {
        let data = res.data
        this.setState({ data, loading: false });
        console.log(data)
      });
  }

  render() {
    if (this.state.loading) {
      return <Loader />
    }

    else 
    return (
       this.state.data.data.map((item) => (
          <>
          <marquee direction="left" behaviour="scroll">
            <p key={item.id}>{item.body} </p>
            </marquee>
          </>
        ))

And I can't find a way to print specific "title" or "body" values, only every output in the array.

Currently my only idea is to use .slice() to manipulate the data the way I want, but this seems like a dirty way of fixing my issue.

Any advice/guidance greatly appreciated, thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Unpacking fields from objects passed as a function parameter can do this.

const user = {
id: 42,
displayName: 'jdoe',
fullName: {
firstName: 'John',
lastName: 'Doe'
  }
};


function userId({id}) {
return id;
 }

function whois({displayName, fullName: {firstName: name}}) {
return `${displayName} is ${name}`;
 }

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!