Reputation: 12190
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
Upvotes: 7
Views: 13622
Reputation: 567
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 });
Upvotes: 13
Reputation: 61
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.
Upvotes: 6