-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (32 loc) · 1.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
exports.changeAttributeOfObject = function(oldField, newField, objects){
var status = true;
// checking the data is in object format or not
if(typeof objects === 'object'){
if(Object.keys(objects).length > 0){
for(key in objects){
if(key == oldField){
objects[ newField] = objects[oldField];
delete objects[oldField];
}else{
var newObject = objects[key];
if(Object.keys(newObject).length > 0){
for(var key1 in newObject){
if(key1 == oldField){
newObject[newField] = newObject[oldField];
delete newObject[oldField];
}
}
}else{
status = false;
}
}
}
// console.log(objects)
return objects;
}else{
console.log('Sorry, your object is empty.');
}
}else{
console.log('Sorry, please your data not in an object format.');
}
}