js 把一個數組的值符合賦值給另一個數組 IE不支持Object.assign


var a=[1,2,3];

var b=[5,6,7];

b=b.concat(a);

console.log(b);

輸出結果:[1,2,3,5,6,7]

 

iE不支持使用assign可以使用var obj = jQuery.extend(formconfig2,data);來代替

或者可以添加以下代碼

if (typeof Object.assign != 'function') {
Object.assign = function(target) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}

target = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source != null) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
}
var obj = Object.assign(formconfig2,data);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM