var xx1 = ["乐谱中的调号为( )调", "写出a自然小调音阶。", "以G为冠音,构写增四、减五音程。", "调式分析。", "将下列乐谱移为C大调。", "正确组合以下乐谱。", "以下乐谱应如何正确组合( )"]; var xx2 = {"0分":{"乐谱中的调号为( )调":"2","调式分析。":"2","将下列乐谱移为C大调。":"2","正确组合以下乐谱。":"2","以下乐谱应如何正确组合( )":"2"},"10分":{"以G为冠音,构写增四、减五音程。":"2"},"20分":{"写出a自然小调音阶。":"2"}}; console.log(xx1); console.log(xx2); function getData(score, list, result){ var target = result[score] || {}; var arr = []; for(var i=0; i<list.length; i++){ arr.push( parseInt(target[list[i]] || 0) ); } return arr; } var a = getData('0分' , xx1, xx2) console.log('0分 ' + a) var a = getData('20分' , xx1, xx2) console.log('20分 ' + a) var a = getData('10分' , xx1, xx2) console.log('10分 ' +a)