Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 910e2cb

Browse files
authored
Create renameObjectKey.js
1 parent 08bd942 commit 910e2cb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎js-coding-technique/renameObjectKey.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const renameObjectKey = ({ oldObj, oldName, newName }) => {
2+
const newObj = {};
3+
Object.keys(oldObj).forEach((key) => {
4+
const value = oldObj[key];
5+
6+
if (key === oldName) {
7+
newObj[newName] = value;
8+
} else {
9+
newObj[key] = value;
10+
}
11+
});
12+
13+
return newObj;
14+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /