Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jquery中将数组列表连接到常量值_Javascript_C# - Fatal编程技术网

Javascript 如何在jquery中将数组列表连接到常量值

Javascript 如何在jquery中将数组列表连接到常量值,javascript,c#,Javascript,C#,我在jQuery中有一个名为Assignedmonth的变量,它存储从下拉列表中选择的多个项 AssignedMonth = $('#dlAssignedMonth :selected').map(function () { return $(this).text(); }).get(); 还有一个变量AssignedYear,它只存储从列表中选择的一个项目 AssignedYear = $('#dlAssignedYear').val(); 现在我想连接这两个变量,并希望得到以下格式的结果

我在jQuery中有一个名为Assignedmonth的变量,它存储从下拉列表中选择的多个项

AssignedMonth = $('#dlAssignedMonth :selected').map(function () { return $(this).text(); }).get();
还有一个变量AssignedYear,它只存储从列表中选择的一个项目

AssignedYear = $('#dlAssignedYear').val();
现在我想连接这两个变量,并希望得到以下格式的结果

Jan-2017
Feb-2017
Mar-2017
这个月剩下的时间也是如此

我在js文件中尝试了$.each函数,但没有得到想要的结果。

返回前只需在$this.text前面加上年份前缀

var year = $('#dlAssignedYear').val();

var output = $('#dlAssignedMonth :selected').map( function () { 
  return year + " " + $(this).text();  //this line has been changed to prefix year
}).get();
您可以对JS中的数组和ES-6中的模板字符串使用map函数来简化字符串

var result = AssignedMonth.map(function(month){
    return `${month}-${AssignedYear}`;
})