Reputation: 570
Hypothetically if we have an object like:
data = {
a: 3,
b: 7,
c: 94,
d: 854
}
How could I get the values corresponding to a array of keys using vanilla javascript or jQuery? So Something similar to:
var keys = ["a", "d"]
Object.values(data)[keys]
So the output would be an array with the values [3, 854]
Upvotes: 0
Views: 298
Reputation: 1175
You can use map
const data = {
a: 3,
b: 7,
c: 94,
d: 854
}
var keys = ["a", "d"]
const result = keys.map(rec => data[rec])
console.log(result)
Upvotes: 4