【发布时间】:2020-12-13 02:48:41
【问题描述】:
我有一个包含多个元素的数组:
var arrayData = [
customerId: "123", mobileNumber: "999"},
customerId: "122", mobileNumber: "998"},
customerId: "121", mobileNumber: "997"}
];
我需要将其转换为如下所示的 XML:
<Result>
<customerId>123</customerId>
<mobileNumber1>999</mobileNumber>
<customerId>122</customerId>
<mobileNumber1>998</mobileNumber>
<customerId>121</customerId>
<mobileNumber1>997</mobileNumber>
</Result>
我尝试了以下方法:
arrayData.map(obj => `<Result><customerId>${obj.customerId}</customerId><mobileNumber>${obj.mobileNumber}</mobileNumber></Result>`).join('');
但我在占位符中不可用,知道如何实现这一点吗?
【问题讨论】:
标签: javascript arrays xml multidimensional-array foreach