I have array of objects and arrays.
If the array of objects has value property same
and if
placeincludes of arrraylistlistreturn first objand if
placeis equal includes/not includes return first obj
if no above conditions return undefined; using javascript
var list=['SG','TH','MY']
var arrobj1=[
{id:1, name:'userone',place:'SG', value:100},
{id:2, name:'usertwo',place:'TH', value:100},
{id:3, name:'userthree',place:'IL',value:200},
]
Expected Output
{id:1, name:'userone',place:'SG', value:100}
****
var arrobj2=[
{id:1, name:'userone',place:'IN', value: 200},
{id:2, name:'usertwo',place:'SL',value: 100},
{id:3, name:'userthree',place:'SL', value: 100},
]
Expected Output
{id:2, name:'usertwo',place:'SL',value: 100}
****
var arrobj3=[
{id:1, name:'userone',place:'SL', value:10},
{id:2, name:'usertwo',place:'IN', value:20},
{id:3, name:'userthree',place:'KL', value:30},
]
Expected Output
undefined
Tried
var result= arrobj.find(e=>{
if((e.value === e.value) && (list.includes(e.place)){
return e
}
})
value property same? Please clarify your conditions and perhaps show us how you're trying to meet them in your code.placevalue is in the list, or (failing that) the first whose place is also duplicated in the duplicate values list? This is another example where most of the analytical work must take place in the problem statement. For example, stackoverflow.com/questions/71900081/…