我想創建一個函數,將採取單詞列表 - 並將其轉換爲像這樣的句子。Javascript逗號清單,但有一個,並在最後一個
的jsfiddle
http://jsfiddle.net/0ht35rpb/107/
//數組列表
"contents": {
"0": ["emotional distress", "behavioural difficulties", "hyperactivity and concentration difficulties", "difficulties in getting along with other young people"],
"5": ["kind and helpful behaviour"]
}
//句子
"<p>Score for emotional distress, behavioural difficulties, hyperactivity and concentration difficulties very high and difficulties in getting along with other young people very high</p>
<p>Score for kind and helpful behaviour very low</p>"
//當前功能
grammarCheck : function(vals) {
//x,y,z and d
//z
var count = vals.length;
var text = vals.join(', ')
//return [ this.props.data.contents[key].slice(0, -1).join(", "), this.props.data.contents[key].slice(-1)[0] ].join(this.props.data.contents[key].length < 2 ? "" : " and ");
return text
}
什麼是錯誤? – SuperStormer
那麼錯誤 - 或者只是做一個逗號列表 - 或者不放在文本的正確部分。 –
// x,y,z,d ---代替// x,y,z和d –