I’m trying to iterate through an array of unknown properties to find a value that exists within a JSON object although there can exist many objects as well, how can I approach this?
args1 = ['string', 5, 3, { value: 'value', number: 2, token: 'token' }];
args2 = [
'string',
{ token: 'token', name: 'name' },
1,
3,
2,
{ book: 'book' },
];
How would i be able to find the property token regardless where it exists like the two examples above?
>Solution :
May be something like this:
let args1 = ['string', 5, 3, { value: 'value', number: 2, token: 'token' }];
args1.filter(x=> typeof x==='object').find(y => console.log(y.token));