Reputation: 7
I have two objects like this
let a = { pending: '500', answer: '200', reject: '400' }
let b ={ Pending: 'pending', Answer: 'answer', Reject: 'reject' }
and now I want loop in the objects for this like:
const C = [{status:200,title:"answer"},{status:400,title:"reject"}, {status:500,title:"pendeing"}]
i can do it?? how
Upvotes: 0
Views: 166
Reputation: 133
just you can use a array and a object
let Object1 = { pending: '500', answer: '200', reject: '400' }
let Object2 =['pending', 'answer', 'reject']
let array =[]
for (let i = 0; i<Object2.length; i++) {
array.push({status: Object1[Object2[i]], title:Object2[i]})
}
console.log(array)
Upvotes: 0
Reputation: 17382
You don't seem to need b
for that at all
The simplest would probably be
var a = { pending: '500', answer: '200', reject: '400' }
var c = Object.entries(a).map(([title, status]) => ({status: +status, title}))
console.log(c);
Upvotes: 0
Reputation: 336
I think b must be a tab like this:
let b = ['pending', 'answer', 'reject']
And we can have c with this code:
var a = { pending: '500', answer: '200', reject: '400' }
var b =['pending', 'answer', 'reject']
let c =[]
for (let i = 0; i<b.length; i++) {
c.push({status: a[b[i]], title:b[i]})
}
console.log(c)
Upvotes: 1