I have one array of object.
Objs[0] = {Name : "ABC"};
Objs[1] = {Roll : 123}
I want to merge both, It will be like
Objs {
Name : "ABC",
Roll : 123
}
Any way to I achieve this?
I have one array of object.
Objs[0] = {Name : "ABC"};
Objs[1] = {Roll : 123}
I want to merge both, It will be like
Objs {
Name : "ABC",
Roll : 123
}
Any way to I achieve this?
You can use Object.assign
method.
var Objs = [{
Name: "ABC"
}, {
Roll: 123
}];
console.log(
Object.assign.apply(null, [{}].concat(Objs))
)
Or you can use spread syntax instead of Function#apply
method.
var Objs = [{
Name: "ABC"
}, {
Roll: 123
}];
console.log(
Object.assign({}, ...Objs)
)
You can try below code.
var jsonObj = {};
$.each(Objs, function(index) {
$.each(Objs[index], function(key, value) {
jsonObj[key] = value;
});
});