Reputation: 171
{
"vendorName": "RAKESH KUMAR",
"vendorContact": "8876545678",
"vendorPAN": "ATMPB6657F",
"vendorBankDetails": [
{
"vendorAccount": "3456787654",
"vendorBankCode": "AXIS123",
"vendorBankName": "AXIS BANK"
}
],
"createdAt": "2021-09-01 00:18:10"
}
to
[0:{
"vendorName": "RAKESH KUMAR",
"vendorContact": "8876545678",
"vendorPAN": "ATMPB6657F",
"vendorBankDetails": [
{
"vendorAccount": "3456787654",
"vendorBankCode": "AXIS123",
"vendorBankName": "AXIS BANK"
}
],
"createdAt": "2021-09-01 00:18:10"
}]
Upvotes: 0
Views: 42
Reputation: 78
let myObjects = [];
myObject.push({"vendorName":"RAKESH KUMAR","vendorContact":"8876545678","vendorPAN":"ATMPB6657F","vendorBankDetails":[{"vendorAccount":"3456787654","vendorBankCode":"AXIS123","vendorBankName":"AXIS BANK"}],"createdAt":"2021-09-01 00:18:10"});
console.log(myObject);
Upvotes: 0
Reputation: 311316
It seems you're just creating an array with a single element which is the aforementioned object. You can do this by surrounding the object with square brackets:
const myArray = [myObject];
Upvotes: 2