用数组包装字符串类型的对象属性-JavaScript
为此,请将Object.keys()与一起使用reduce()。为了显示结果,我们还将使用concat()。
示例
以下是代码-
var details = { name: ["John", "David"], age1: "21", age2: "23" },
output = Object
.keys(details)
.reduce((obj, tempKey) =>
(obj[tempKey] = [].concat(details[tempKey]), obj), {})
console.log(output)要运行上述程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo302.js。
输出结果
这将在控制台上产生以下输出-
PS C:\Users\Amit\javascript-code> node demo302.js
{ name: [ 'John', 'David' ], age1: [ '21' ], age2: [ '23' ] }热门推荐
10 小学毕业父母简短祝福语
11 幼儿生日祝福语模板简短
12 新娘妈妈的祝福语简短
13 邻居聚会祝福语大全简短
14 十条祝福语简短
15 给同学祝福语的简短
16 过年祝福语简短祝妈妈
17 祝女儿简短祝福语大全
18 恩师诗词祝福语简短大全