0

I have an object which I got from an API call. I have passed the object through route.params I want to take warrantyStatus from the tasks array for specific serialNumber which I got from route.params. I pass the serialNumber through route.params as PSerial following is my Object

      "tasks": Array [
        Object {
          "completed": false,
          "createdAt": null,
          "model": "Lexmark:T650N",
          "product": "Printer",
          "remark": "POWER SUPPLY UNIT NOT WORKING",
          "serialNumber": "794DCYL",
          "status": null,
          "topic": "21081235T69",
          "ttId": 27945,
          "warrantyStatus": "MAINTENANCE_COMPREHENSIVE",
        }, ]

I have taken the serialNumber as PSerial from route.params. So I want to take out the warrantyStatus and show in a Text tag

1 Answer 1

1

You can filter your tasks array based on PSerial and the warrantyStatus property.

Simply find the item with,

const item = tasks.find(item => item.serialNumber === PSerial)

Now the item will have the corresponding matching object. You can access the warrantyStatus by item.warrantyStatus and show it in a Text component.

You can use the array filter function if you are expecting multiple tasks to have the same warrantyStatus property.

const items = tasks.filter(item => item.serialNumber === PSerial)

The items now will be an array having all tasks matching the provided PSerial value.

Sign up to request clarification or add additional context in comments.

7 Comments

i added it but it shows me as iitem : Array [] & console log. const item = dataOBJ.tasks.filter(item => item.warrantyStatus === PSerial) console.log("iitem :",item)
that means no items match with the given PSerial value, hence empty array as result
I added this dataOBJ.tasks.find(item => item.warrantyStatus === PSerial) is it ok beacuse you have missed the dataOBJ.tasks at the answer
const item = (dataOBJ.tasks) console.log("iitem :",item) this was the console.log iitem : Array [ Object { "completed": false, "createdAt": null, "model": "Lexmark:MS510DN", "product": "PRINTER", "remark": "paper jam", "serialNumber": "451444HH1N1GT", "status": null, "topic": "21080295T210", "ttId": 27226, "warrantyStatus": "MAINTENANCE_COMPREHENSIVE", }, ]
PSerial = serialNumber in the array. Tasks Array has multiple Objects. can you look in to that
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.