0

I have a problem about how to change object properties name. I have a object like this:


description: "Human Resource Management Module"

id: 8

route: "/apps"

__children: Array(2)

How can i change __children properties name to indexSearch?

1
  • Not really a typescript issue but an IDE one. Right click and "Rename" should do the trick ! Commented Jul 11, 2017 at 7:32

2 Answers 2

5

I assume you are looking for solution to change object properties programmatically. you can assign the value of old property(__children) to a new one(indexSearch) and then delete the old property.

obj['indexSearch'] = obj['__children'];
delete obj['__children'];

see the below example.

var obj = {
  description: "Human Resource Management Module",
  id: 8,
  route: "/apps",
  __children: ['item1', 'item2']
};

console.log(obj)

obj['indexSearch'] = obj['__children'];
delete obj['__children'];

console.log(obj)

Sign up to request clarification or add additional context in comments.

2 Comments

it is not working in typescipt..
@Ozmen Typescript uses static types. You have to define the old and new fields first in your type declearation.
-3

You can rename it like this, it's pretty simple:

enter image description here

You will have to use the keyboard, potentially the mouse as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.