Answer the question
In order to leave comments, you need to log in
How to convert an object?
Hello!
How to add a new value to an object while keeping the old data.
For example:
I have an array of object with data:
interface Chelsea {
name: string;
age: number;
}
data = [
{"name": "Terry", "age": 20},
{"name": "Lampard", "age": 18},
{"name": "Drogba", "age": 15},
];
interface Chelsea2 extends Chelsea {
country: string;
}
data = [
{"name": "Terry", "age": 20, "city": "England"},
{"name": "Lampard", "age": 18, "city": "England"},
{"name": "Drogba", "age": 15, "city": "Cote Divuar"},
];
Answer the question
In order to leave comments, you need to log in
So? Or what are you asking? And what do you want from inheritance?
data.forEach(function(e) {
e.country = 'Hello world';
})
https://jsfiddle.net/t3e61bu5/
Why is there inheritance?
var data = [
{"name": "Terry", "age": 20, "city": "England"},
{"name": "Lampard", "age": 18, "city": "England"},
{"name": "Drogba", "age": 15, "city": "Cote Divuar"},
];
Object.defineProperty(data, 'country', {value: 'string'});
console.log("data.country= ", data.country);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question