[英]How to make Object value to Object property in JavaScript
I have an Object named category .我有一个名为category的对象。 Here the
property/keys
are in short-form and the value
is in fullform .这里的
property/keys
是短格式, value
是fullform 。 I need to assign Object property/keys
to Object value
for a short time moment .我需要在短时间内将 Object
property/keys
分配给 Object value
。
Like.喜欢。
'Technology' have to make tech
“技术”必须创造技术
const category = { tech: 'Technology', gnr: 'General', ent: 'Entertainment', sci: 'Science', } let aa=Object.values(category).map(i=>{ Object.keys(category).map(j=>{ i=j }) }) console.log(a)
const categories = {
tech: 'Technology',
gnr: 'General',
ent: 'Entertainment',
sci: 'Science',
}
const predicate = 'General';
let match;
for (const category in categories) {
if (categories[category] === predicate) {
match = category;
}
}
console.log(match);
let a = {};
for (let key in category)
{
a[category[key]] = key;
}
or或者
let a = {};
Object.entries(category).forEach(kv=>a[kv[1]]=kv[0]);
Nope!不! Now after getting match with parameter that I will pass, I need that matching parameter Object Value's
Property/Keys
.现在在与我将传递的参数匹配后,我需要匹配参数 Object Value's
Property/Keys
。
Like, If General Match then I need gnr就像,如果一般匹配,那么我需要gnr
Here I am getting 'General'
but I need gnr
在这里,我得到了
'General'
但我需要gnr
const category = { tech: 'Technology', gnr: 'General', ent: 'Entertainment', sci: 'Science', } let aa=Object.values(category).filter(i=>{ if(i=='General') { return Object.keys(i) } }) console.log(a)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.