【发布时间】:2019-08-21 13:30:09
【问题描述】:
FROM HERE:(这个数组是调用响应)
[
{ "DAY": 20190323,"NAME": "BTA130", "STREAMNAME": "Instant Purification, Pentatone A/B , This is a drill"},
{ "DAY": 20190324,"NAME": "BTA130", "STREAMNAME": "Instant Purification, Pentatone A/B , This is a drill"},
{ "DAY": 20190325,"NAME": "BTA130", "STREAMNAME": "Instant Purification, Pentatone A/B , This is a drill"},
{ "DAY": 20190326,"NAME": "BTA130", "STREAMNAME": "Instant Purification, Pentatone A/B , This is a drill"},
{ "DAY": 20190327,"NAME": "BTA130", "STREAMNAME": "Instant Purification, Pentatone A/B , This is a drill"},
]
到这里:
[
[20190323, "Instant Purification", "Pentatone A/B" , "This is a drill"],
[20190324, "Instant Purification", "Pentatone A/B" , "This is a drill"],
[20190325, "Instant Purification", "Pentatone A/B" , "This is a drill"],
[20190326, "Instant Purification", "Pentatone A/B" , "This is a drill"],
[20190327, "Instant Purification", "Pentatone A/B" , "This is a drill"]
]
所以我做到了:
const yearDays = res.map(x => x['YEAR_DAY']);
const streams = res.map(x => x['STREAMNAME']);
const labeler = yearDays.map((v, i) => {return [v, String(streams[i]).split(/\s*(?:,|$)\s*/)]; });
INSTEAD IVE GOT:(有点接近但不是真的)
[20190323, ["Instant Purification", "Pentatone A/B" , "This is a drill"]
[20190324, ["Instant Purification", "Pentatone A/B" , "This is a drill"]
[20190325, ["Instant Purification", "Pentatone A/B" , "This is a drill"]
...
如何从内部数组中取出所有元素并使它们成为外部数组的一部分?
【问题讨论】:
-
@MaheerAli 怎么样?
-
可能我复制错了。坚持
-
再说一次,怎么会这样?这是一个带逗号的字符串。
-
@JackBashford 对不起,我的错误,代码很好。
-
我已更新数组并将逗号放在末尾。还在 json 验证器上对其进行了验证。现在应该好了
标签: javascript arrays angular ecmascript-6