7

I have the following object:

var Customers = {
 name = 'John',
 last = 'Doe'
}

I have imported to my react component, I'm having difficulty looping through object content.

Here is what I have tried

import Customers from './customer';

var customer = Customers.map(function(s){ return s.name });

I'm getting the following error

Uncaught ReferenceError: name is not defined(…)(anonymous 

2 Answers 2

13

Also, you can't use map for objects like this. You should write

var customer = Object.keys(Customers).map(function(s){ return Customers[s].name });
Sign up to request clarification or add additional context in comments.

Comments

6

Instead of equals name='John' it's suppose to be name : 'John'.

If you are trying to retrieve the name you could access the variable like Customers.name. If you are trying to do something more with it let me know and I am more than happy to help.

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.