I have a ridiculous object like this.
{
order: ["a1","a2","a3","a4"],
posts: {
a1: {id: "a1",message: "This is a1"},
a4: {id: "a4",message: "This is a4"},
a3: {id: "a3",message: "This is a3"},
a2: {id: "a2",message: "This is a2"},
}
}
I need to get "message" value from "posts" object with the order that define in "order" array. I can foreach the "order" array, but how to know when I have "a1" string, I need to take "a1" object in "posts" object?
Thank you!
const str = 'a1'; obj.posts[str]??? It's not clear what you're asking