我有一个像这样的数组
var Data = [{
"words": [
"dolor",
"sit",
"amet",
"consectetur"
],
"description": "Lorem Ipsum."
}, {
"words": [
"adipisicing",
"elit",
"sed",
"do"
],
"description": "Lorem Ipsum."
}];
如何将所有单词连接成一个字符串,用单个管道符号“|”分隔? 所需的输出应如下所示: (dolor | sit | amet | consectetur | adipisicing | elit | sed | do)
答案 0 :(得分:7)
这样做
Data.map(function(obj){ return obj.words.join("|") }).join("|");
返回 “悲|坐|阿梅特| consectetur | adipisicing | ELIT | sed的|做”