-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (47 loc) · 1.01 KB
/
index.js
File metadata and controls
51 lines (47 loc) · 1.01 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var obj = {
user_list: [
{
user_id: "1234",
nick_name: "aaaa",
friends: [{ user_id: "2222", nick_name: "bbbb" }],
},
{
userId: "1244",
nick_name: "aaaa",
},
],
};
var newObj = {};
var translate = function (oldObj, newObj) {
for (let key in oldObj) {
if (oldObj.hasOwnProperty(key)) {
const newKey = toUpper(key);
if (oldObj[key] instanceof Array) {
newObj[newKey] = [];
oldObj[key].forEach((item, index) => {
newObj[newKey][index] = {};
translate(item, newObj[newKey][index]);
});
} else {
newObj[newKey] = oldObj[key];
}
}
}
};
var toUpper = function (key) {
return key.replace(/_(\w)/g, (all, letter) => {
return letter.toUpperCase();
});
};
// translate(obj, newObj);
// console.log(JSON.stringify(newObj));
var obj = {
'2': 3,
'3': 4,
'length': 2,
'splice': Array.prototype.splice,
'push': Array.prototype.push
}
obj.push(1);
obj.push(2);
console.log(obj);