I have an array of all items ids:
(我有所有项目ID的数组:)
const allIds = ['a1gb', 'f4qa', 'i9w9']
I also have an object with it's properties having those ids as keys:
(我还有一个对象,它的属性具有这些id作为键:)
const byId = {
a1gb: {
whatever1
},
anyOtherIdThatIDontNeed: {
whatever444
},
f4qa: {
whatever2
},
i9w9: {
whatever3
}
}
What is the most common way to return an array that would look like
(返回看起来像这样的数组的最常见方法是什么)
[ { whatever1 }, { whatever2 }, { whatever3 } ]
and skip the Ids I don't want in my final array?
(并跳过我不想在最终数组中使用的ID?)
This a log of the array with the ids:
(这是具有ID的数组的日志:)
This is a log of the object from which I need to return an array with the values of the keys from that array of ids skipping the ones I don't need:
(这是对象的日志,我需要从该对象返回一个数组,其中包含该ID数组中的键值,并跳过了不需要的键:)
PS Problem is that in that return array from the map function I get undefined when it encounters "anyOtherIdThatIDontNeed:".
(PS问题是,在映射函数的返回数组中,当遇到“ anyOtherIdThatIDontNeed:”时,我无法定义。)
PPS[ ANSWER ] - The array of Ids had ids that do not match object's keys and that is why I was getting undefined.
(PPS [ANSWER]-ID数组的ID与对象的键不匹配,这就是为什么我不确定的原因。)
ask by Mihai Ciobanu translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…