Hello everyone I’m new to postman but I must perform a test to verify the status of the characters (alive / dead) in the rickandmorty API, I am trying to filter that information through this code, but I persist the following error in the console: TypeError: response.filter is not a function
https://rickandmortyapi.com/api/character/?page=40
"info": {
"count": 826,
"pages": 42,
"next": "https://rickandmortyapi.com/api/character/?page=41",
"prev": "https://rickandmortyapi.com/api/character/?page=39"
"results": [
"id": 781,
"name": "Rick's Garage",
"status": "Alive",
"species": "Robot",
"type": "Artificial Intelligence",
"gender": "Female",
"origin": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"location": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"image": "https://rickandmortyapi.com/api/character/avatar/781.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/49"
"url": "https://rickandmortyapi.com/api/character/781",
"created": "2021-10-25T09:18:48.188Z"
"id": 782,
"name": "Memory Squanchy",
"status": "Dead",
"species": "Alien",
"type": "Memory",
"gender": "Male",
"origin": {
"name": "Birdperson's Consciousness",
"url": "https://rickandmortyapi.com/api/location/120"
"location": {
"name": "Birdperson's Consciousness",
"url": "https://rickandmortyapi.com/api/location/120"
"image": "https://rickandmortyapi.com/api/character/avatar/782.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/49"
"url": "https://rickandmortyapi.com/api/character/782",
"created": "2021-10-25T09:20:57.545Z"
"id": 783,
"name": "Memory Rick",
"status": "Dead",
"species": "Human",
"type": "Memory",
"gender": "Male",
"origin": {
"name": "Birdperson's Consciousness",
"url": "https://rickandmortyapi.com/api/location/120"
"location": {
"name": "Birdperson's Consciousness",
"url": "https://rickandmortyapi.com/api/location/120"
"image": "https://rickandmortyapi.com/api/character/avatar/783.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/49"
"url": "https://rickandmortyapi.com/api/character/783",
"created": "2021-10-25T09:22:40.448Z"
"id": 784,
"name": "Memory Rick",
"status": "Dead",
"species": "Human",
"type": "Memory",
"gender": "Male",
"origin": {
"name": "Birdperson's Consciousness",
"url": "https://rickandmortyapi.com/api/location/120"
"location": {
"name": "Birdperson's Consciousness",
"url": "https://rickandmortyapi.com/api/location/120"
"image": "https://rickandmortyapi.com/api/character/avatar/784.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/49"
"url": "https://rickandmortyapi.com/api/character/784",
"created": "2021-10-25T09:23:22.034Z"
"id": 785,
"name": "Memory Geardude",
"status": "Dead",
"species": "Alien",
"type": "Memory",
"gender": "Male",
"origin": {
"name": "Birdperson's Consciousness",
"url": "https://rickandmortyapi.com/api/location/120"
"location": {
"name": "Birdperson's Consciousness",
"url": "https://rickandmortyapi.com/api/location/120"
"image": "https://rickandmortyapi.com/api/character/avatar/785.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/49"
"url": "https://rickandmortyapi.com/api/character/785",
"created": "2021-10-25T09:24:51.284Z"
"id": 786,
"name": "Birdperson & Tammy's Child",
"status": "Alive",
"species": "Humanoid",
"type": "Bird-Person Human Mix",
"gender": "Female",
"origin": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"location": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"image": "https://rickandmortyapi.com/api/character/avatar/786.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/49"
"url": "https://rickandmortyapi.com/api/character/786",
"created": "2021-10-25T09:27:05.325Z"
"id": 787,
"name": "Two Crows",
"status": "Alive",
"species": "Animal",
"type": "Crow",
"gender": "unknown",
"origin": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"location": {
"name": "Rick and Two Crows Planet",
"url": "https://rickandmortyapi.com/api/location/125"
"image": "https://rickandmortyapi.com/api/character/avatar/787.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/50",
"https://rickandmortyapi.com/api/episode/51"
"url": "https://rickandmortyapi.com/api/character/787",
"created": "2021-10-25T09:31:47.377Z"
"id": 788,
"name": "Mr. Cookie President",
"status": "Alive",
"species": "Alien",
"type": "Cookie",
"gender": "Male",
"origin": {
"name": "unknown",
"url": ""
"location": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"image": "https://rickandmortyapi.com/api/character/avatar/788.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/50"
"url": "https://rickandmortyapi.com/api/character/788",
"created": "2021-10-25T10:18:19.997Z"
"id": 789,
"name": "Nick",
"status": "Dead",
"species": "Human",
"type": "",
"gender": "Male",
"origin": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"location": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"image": "https://rickandmortyapi.com/api/character/avatar/789.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/50"
"url": "https://rickandmortyapi.com/api/character/789",
"created": "2021-10-25T10:19:06.159Z"
"id": 790,
"name": "Harold (Garbage Goober)",
"status": "Alive",
"species": "Alien",
"type": "",
"gender": "Male",
"origin": {
"name": "unknown",
"url": ""
"location": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"image": "https://rickandmortyapi.com/api/character/avatar/790.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/50"
"url": "https://rickandmortyapi.com/api/character/790",
"created": "2021-10-25T10:20:33.373Z"
"id": 791,
"name": "Harold's Wife",
"status": "Alive",
"species": "Alien",
"type": "",
"gender": "Female",
"origin": {
"name": "unknown",
"url": ""
"location": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"image": "https://rickandmortyapi.com/api/character/avatar/791.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/50"
"url": "https://rickandmortyapi.com/api/character/791",
"created": "2021-10-25T10:21:17.779Z"
"id": 792,
"name": "Alien Crow",
"status": "Dead",
"species": "Alien",
"type": "Crow",
"gender": "Male",
"origin": {
"name": "Avian Planet",
"url": "https://rickandmortyapi.com/api/location/122"
"location": {
"name": "Avian Planet",
"url": "https://rickandmortyapi.com/api/location/122"
"image": "https://rickandmortyapi.com/api/character/avatar/792.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/50"
"url": "https://rickandmortyapi.com/api/character/792",
"created": "2021-10-26T14:48:36.728Z"
"id": 793,
"name": "Alien Crow",
"status": "Dead",
"species": "Alien",
"type": "Crow",
"gender": "Female",
"origin": {
"name": "Avian Planet",
"url": "https://rickandmortyapi.com/api/location/122"
"location": {
"name": "Avian Planet",
"url": "https://rickandmortyapi.com/api/location/122"
"image": "https://rickandmortyapi.com/api/character/avatar/793.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/50"
"url": "https://rickandmortyapi.com/api/character/793",
"created": "2021-11-02T13:00:18.318Z"
"id": 794,
"name": "Samansky",
"status": "Dead",
"species": "Alien",
"type": "Normal Size Bug",
"gender": "Male",
"origin": {
"name": "Normal Size Bug Dimension",
"url": "https://rickandmortyapi.com/api/location/123"
"location": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"image": "https://rickandmortyapi.com/api/character/avatar/794.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/48"
"url": "https://rickandmortyapi.com/api/character/794",
"created": "2021-11-02T13:04:18.866Z"
"id": 795,
"name": "Palicki",
"status": "Alive",
"species": "Alien",
"type": "Normal Size Bug",
"gender": "Male",
"origin": {
"name": "Normal Size Bug Dimension",
"url": "https://rickandmortyapi.com/api/location/123"
"location": {
"name": "Normal Size Bug Dimension",
"url": "https://rickandmortyapi.com/api/location/123"
"image": "https://rickandmortyapi.com/api/character/avatar/795.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/48"
"url": "https://rickandmortyapi.com/api/character/795",
"created": "2021-11-02T13:05:12.642Z"
"id": 796,
"name": "Sarge",
"status": "Alive",
"species": "Alien",
"type": "Normal Size Bug",
"gender": "Male",
"origin": {
"name": "Normal Size Bug Dimension",
"url": "https://rickandmortyapi.com/api/location/123"
"location": {
"name": "Normal Size Bug Dimension",
"url": "https://rickandmortyapi.com/api/location/123"
"image": "https://rickandmortyapi.com/api/character/avatar/796.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/48"
"url": "https://rickandmortyapi.com/api/character/796",
"created": "2021-11-02T13:05:42.996Z"
"id": 797,
"name": "Slartivartian",
"status": "Dead",
"species": "Alien",
"type": "Slartivartian",
"gender": "Male",
"origin": {
"name": "Slartivart",
"url": "https://rickandmortyapi.com/api/location/124"
"location": {
"name": "Slartivart",
"url": "https://rickandmortyapi.com/api/location/124"
"image": "https://rickandmortyapi.com/api/character/avatar/797.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/44"
"url": "https://rickandmortyapi.com/api/character/797",
"created": "2021-11-02T13:07:40.795Z"
"id": 798,
"name": "Ferkusian",
"status": "Alive",
"species": "Alien",
"type": "Ferkusian",
"gender": "Male",
"origin": {
"name": "Ferkus 9",
"url": "https://rickandmortyapi.com/api/location/113"
"location": {
"name": "Ferkus 9",
"url": "https://rickandmortyapi.com/api/location/113"
"image": "https://rickandmortyapi.com/api/character/avatar/798.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/44"
"url": "https://rickandmortyapi.com/api/character/798",
"created": "2021-11-02T13:09:10.765Z"
"id": 799,
"name": "Morglutzian",
"status": "Dead",
"species": "Alien",
"type": "Morglutzian",
"gender": "Male",
"origin": {
"name": "Morglutz",
"url": "https://rickandmortyapi.com/api/location/112"
"location": {
"name": "Morglutz",
"url": "https://rickandmortyapi.com/api/location/112"
"image": "https://rickandmortyapi.com/api/character/avatar/799.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/44"
"url": "https://rickandmortyapi.com/api/character/799",
"created": "2021-11-02T13:09:51.886Z"
"id": 800,
"name": "Super Turkey",
"status": "Dead",
"species": "Humanoid",
"type": "Turkey Human Mix",
"gender": "Male",
"origin": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"location": {
"name": "Earth (Replacement Dimension)",
"url": "https://rickandmortyapi.com/api/location/20"
"image": "https://rickandmortyapi.com/api/character/avatar/800.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/47"
"url": "https://rickandmortyapi.com/api/character/800",
"created": "2021-11-02T13:11:52.372Z"
and this is my code but it gives me the error I mentioned before
const response = pm.response.json();
console.log(response)
const characterAlives = response.filter((results) => results.status === "Alive");
console.log(characterAlives);
const results = characterAlives[0];
console.log(results);
pm.test('Character found by Alive', ()=> {
pm.expect(results.status).to.eql("Alive")
anyone can help me pls?
Use this one. You need to first get the results object in order to access the objects inside. Currently response holds full response and first access results from response.
const characterAlives = response.results.filter((results) => results.status === "Alive");