1

this code works perfectly on my browser but when i applied it on react native i have an error of

" Possible Unhandled Promise Rejection (id: 0): TypeError: obj.room_type_id.includes is not a function. (In 'obj.room_type_id.includes(id)', 'obj.room_type_id.includes' is undefined) "

var data = [{
  "floor": "1st",
  "name": "NAME0",
  "room_type_id": ["Y", "B", "S", "N"],
  "status": "Available"
}, {
  "floor": "7",
  "name": "NAME54",
  "room_type_id": ["O", "G", "C", "S"],
  "status": "Available"
}, {
  "floor": "64",
  "name": "NAME2",
  "room_type_id": ["A", "S", "Q", "D"],
  "status": "Available"
}, {
  "floor": "Bddh",
  "name": "NAME3",
  "room_type_id": ["A", "X", "S", "D"],
  "status": "Available"
}, {
  "floor": "Vh",
  "name": "NAME1",
  "room_type_id": ["A", "B", "C", "D"],
  "status": "Available"
}, {
  "floor": "Dyd",
  "name": "NAME2",
  "room_type_id": ["A", "B", "C", "D"],
  "status": "Available"
}]

let id = "B";
let dataResult = data.filter((obj) => obj.room_type_id.includes(id)).length;


console.log(dataResult)

2
  • You need to check what obj.room_type_id returns: based on the error message, it does not appear to be an array when the .filter() callback is invoked. Commented Feb 22, 2021 at 7:19
  • it is Json object ! parse it to js then use it as you did Commented Feb 22, 2021 at 8:51

1 Answer 1

1

Have a try by parsing the array object to the JSON object to use the array itteration methods.

let JSONData = JSON.parse(JSON.stringify(data))
let dataResult = JSONData.filter((obj) => obj.room_type_id.includes(id)).length;
Sign up to request clarification or add additional context in comments.

Comments

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.