Skip to content

Commit

Permalink
Create 对象的键值对的key排序.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Rain120 authored Apr 4, 2018
1 parent 6d87b16 commit 929a957
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 对象的键值对的key排序.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 根据对象的键值对的key排序

function objSortByKey (obj) {
var newKey = Object.keys(obj).sort();
var newObj = {};
for (var i in newKey) {
newObj[newKey[i]] = obj[newKey[i]];
}
return newObj;
}
var obj = {
js: 'Javascript',
html: 'HTML',
vue: 'Vue',
react: 'React',
css: 'CSS'
};
objSortByKey(obj);

0 comments on commit 929a957

Please sign in to comment.