Im trying to serach the key named "SerialNumber" in array of objects and replace with "SNo"
var object = [{
"SerialNumber": 001,
"name": "user1"
}, {
"SerialNumber": 002,
"name": "user2"
}];
if ('SerialNumber' in object[0]) {
object.forEach(function (key) {
key.SNo = key.SerialNumber;
delete key.SerialNumber;
});
}
console.log(object)
if object = [], then the above code is not working. Is there any better approach (with good performance) to search the key in array of objects and replace with the new key.
object[0]As inif (object.length > 0) { ... }And maybe don't call the array object.SerialNumberproperty or not.