Monday, June 3, 2024
130
rated 0 times [  131] [ 1]  / answers: 1 / hits: 39953  / 8 Years ago, tue, april 12, 2016, 12:00:00

I have an object:



languages: {
en:[au, uk],
de:[de],
....
}


How can I remove everything but a specified key, so if I specify 'en' I just want an object that contains en:[au, uk]


More From » javascript-objects

 Answers
73

Simply, you could create a new object with specified field;



var key = 'en';

var o = {
languages: {
en: [au, uk],
de: [de]
}
}

var res = {}

res[key] = o.languages[key];

[#62587] Monday, April 11, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
briarc

Total Points: 402
Total Questions: 85
Total Answers: 114

Location: El Salvador
Member since Sun, Sep 12, 2021
3 Years ago
;