0
我有一個具有多個屬性的對象,如果有多個值,我想用單引號和逗號包裝結果,請參閱下面的提琴。Javascript:將單引號添加到單個對象結果中
http://jsfiddle.net/efv7sh9d/1/
var obj = {
WKF001: ['test1'],
WKF002: ['test2','test3'],
WKF003: ['test4','test5','test6','test7'],
WKF004: ['test8','test8','test9','test10','test11'],
WKF005: ['test12','test13','test14','test15','test16']
}
function returnCodes(wkf, obj) {
for (var d in obj) {
if (d.indexOf(wkf) > -1) {
return obj[d];
}
}
return 'Unknown';
}
var wkftest1 = "WKF001";
var wkftest2 = "WKF002";
var wkftest3 = "WKF003";
document.write(returnCodes(wkftest3, obj).join("','"));
這將返回TEST4' , 'TEST5', 'TEST6', 'TEST7,我需要它是 'TEST4',' TEST5' , 'TEST6', 'TEST7'
'「'」+ joincode +「'」'? – 2014-09-29 14:14:13