javascript - 如何在 Java Script/TestCafe 中获取多个键值对数组
问题描述
const passnegerGroup = [
{ FIRSTNAME: 'RAHUL', LASTNAME: 'KUMAR' },
{ FIRSTNAME: 'RINA', LASTNAME: 'KUMAR' },
{ FIRSTNAME: 'SOHAN', LASTNAME: 'SINGH' },
{ FIRSTNAME: 'PAUL', LASTNAME: 'ANDERSON' },
];
// I want to read each passenger's last name and first name and do some operations.
// Tried this code but this is
for (const key of Object.values(passnegerGroup)) {
console.log(key.FIRSTNAME, key.LASTNAME);
}
输出 :
RAHUL KUMAR RINA KUMAR SOHAN SINGH PAUL ANDERSON
这适用于但出现 ESLINT 错误。
ESLint: iterators/generators require regenerator-runtime
,这对于本指南来说太重了,无法允许它们。另外,应避免循环以支持数组迭代。(无限制语法)
请帮助我使用一些现代 JavaScript/TestCafe 代码实现上述目标。
解决方案
const passnegerGroup = [
{ FIRSTNAME: 'RAHUL', LASTNAME: 'KUMAR' },
{ FIRSTNAME: 'RINA', LASTNAME: 'KUMAR' },
{ FIRSTNAME: 'SOHAN', LASTNAME: 'SINGH' },
{ FIRSTNAME: 'PAUL', LASTNAME: 'ANDERSON' },
];
const result = passnegerGroup.reduce((accum, cur) => `${accum} ${cur.FIRSTNAME} ${cur.LASTNAME} `, '');
console.log('result =', result);
推荐阅读
- javascript - 如何使用正则表达式编写路径
- amazon-web-services - AWS Cloudformation / Codepipeline 参数:[ProjectId] 必须有值
- javascript - Javascript将字符串切成指定长度的块存储在变量中
- sql-server - Docker - 在作曲家之前或之后运行 Dockerfile 如何?
- python - 如何根据已计算的统计数据制作蜡烛图/箱线图?
- javascript - 当使用来自另一个函数的参数单击按钮时,我想将用户重定向到网页?
- python - 使用 multiprocess.Pool 同时运行 2 个应用程序
- c# - C#:设计一个更快的 Assert 函数,仅在触发时格式化错误字符串
- ruby-on-rails - Ruby on Rails 应用程序 - 没有要加载的文件
- excel - 将超过 24 小时的时间转换为 24 小时的时间