0

Take a sample array of objects n number length. on every 3rd and 5th array push new key value "insert:10"

Eg: input: [{id:1},{id:2}.{id:3}] output: [{id:1},{id:2},{id:3,insert:10}]

27th Jun 2022, 10:21 AM
Padala Bala Sirisha
Padala Bala Sirisha - avatar
7 Réponses
+ 1
Just want like this output: [{id:1},{id:2},{id:3,insert:10}, id:4},{id:5,insert:10}, {id:1},{id:2},{id:3,insert:10}, id:4},{id:5,insert:10}]
27th Jun 2022, 11:01 AM
Padala Bala Sirisha
Padala Bala Sirisha - avatar
+ 2
anything you have tried so far ?
27th Jun 2022, 10:43 AM
Abhay
Abhay - avatar
+ 2
Padala Bala Sirisha what do you mean by 3rd and 5th ? Is it like 3,5,7,9 and so on or something else ?
27th Jun 2022, 10:54 AM
Abhay
Abhay - avatar
+ 1
Padala Bala Sirisha let a=[{id:1},{id:2},{id:3}] a.map((item)=>{ if(item.id === 3 || item.id == 5){ item.insert=10 } })
27th Jun 2022, 11:18 AM
Abhay
Abhay - avatar
+ 1
Thank you
27th Jun 2022, 11:22 AM
Padala Bala Sirisha
Padala Bala Sirisha - avatar
0
No
27th Jun 2022, 10:45 AM
Padala Bala Sirisha
Padala Bala Sirisha - avatar
0
This is not getting output
28th Jun 2022, 3:01 AM
Padala Bala Sirisha
Padala Bala Sirisha - avatar