最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React.js iterate through object keys and values using map - Stack Overflow

programmeradmin2浏览0评论

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
Add a comment  | 

2 Answers 2

Reset to default 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 });

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.

发布评论

评论列表(0)

  1. 暂无评论