1

I'm new to React and I'm using JSX with it and I need a way to loop over the array of objects that I have. I used map method, but it gives me this error in the console: TypeError: boxes.map is not a function where boxes is the array containing objects.

Here is my FaceRecognitionList component code:

import React from 'react';
import FaceRecognition from './FaceRecognition';

const FaceRecognitionList = ({ imageUrl, boxes }) => {
    console.log(boxes)
    return (
        <div>
            {
                boxes.map((box, i) => {
                    return (
                    <FaceRecognition
                    key={i}
                    left={boxes[i].leftCol} 
                    top={boxes[i].topRow} 
                    right={boxes[i].rightCol}
                    bottom={boxes[i].bottomRow}
                    imageUrl={imageUrl}
                    />
                );
            })
        }
        </div>
    );
}
export default FaceRecognitionList; 
2
  • what is your console.log of boxes ? please post that array Commented Mar 18, 2020 at 8:41
  • Two objects like this Object { } and Object { } Commented Mar 18, 2020 at 8:43

1 Answer 1

2

Try

Object.entries(boxes).map(([key, vaue]) => console.log(key, value))

Otherwise, try

Object.keys(boxes).map(key => boxes[key])
Sign up to request clarification or add additional context in comments.

1 Comment

Typo - I think it should be Object.entries and not enteries :)

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.