- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 map
返回一个包含每个对象的句子的新数组。
我尝试了一些方法,但似乎无法获得返回每个对象的值的正确逻辑。
这样的对象:
const person = [
{
name: "James",
nationality: "English",
age: 26
},
{
name: "Pierre",
nationality: "French",
age: "23"
}
]
应该返回:
[
"My name is James, I am English and I am 26",
"My name is Pierre, I am French and I am 23"
]
最佳答案
您可以使用map
循环遍历数组。使用Template literals
构造所需的字符串。
const person = [{
name: "James",
nationality: "English",
age: 26
},
{
name: "Pierre",
nationality: "French",
age: "23"
}
];
const result = person.map(o => `My name is ${o.name}, I am ${o.nationality} and I am ${o.age}`);
console.log(result);
关于javascript - 使用map返回一个新数组,每个对象都有一个句子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56408470/
我知道我应该指定 argtypes对于我的 C/C++ 函数,因为我的某些调用会导致堆栈损坏。 myCfunc.argtypes = [ct.c_void_p, ct.POINTER(ct.c
我正在从 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators 学习 Itera
在我的数据库中,我有一个类别表。类别可以有父类别,使其成为递归关系 我还有一个产品表。每个产品都属于一个类别。 例如,我有一棵树,如下所示: Category Sub-Category 1
定义列表要求每个 会有标签? 例子: option1 每个 存在他的如果 空: value1 name2 value2 选项 2 每个 不存在他的如果空: value1 name2 value
我制作了一个脚本,它在开始时检查操作系统版本。 它读取/etc/os-release 文件,并检查操作系统是否为 CentOS 7。 但我不确定我是否可以确保每个 CentOS 7 都有那个文件。 其
我一直在使用 webapi 设置一个 mvc 项目。我可以正常工作,但我不知道为什么我的 GET 调用的 URL 中有附加部分。 示例: /api/User/Zholen?_=137349028082
我创建了具有 ACTIVE BOOL 的基类 class BaseTest{ public: bool active = false; BaseTest(){ // make
.parent { background-color: yellow; display: flex; justify-content: space-evenly; } .parent >
完整的错误是: AttributeError: Neither 'ColumnClause' object nor 'Comparator' object has an attribute 'desc
我的 GUI 中有一些功能可以随着时间的推移更新给定的文本组件。理想情况下,我希望它接受任何具有 getText/setText 方法的内容。使用 JTextField 和 JTextPane 可以轻
我是一名优秀的程序员,十分优秀!