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
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
Share
Improve this question
edited Dec 2, 2016 at 0:21
Deano
asked Dec 2, 2016 at 0:11
DeanoDeano
12.2k20 gold badges75 silver badges125 bronze badges
2 Answers
Reset to default 13Also, you can't use map for objects like this. You should write
var customer = Object.keys(Customers).map(function(s){ return Customers[s].name });
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.